nginx-doc-搭建和使用

安装

推荐安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# 安装gcc
yum -y install gcc-c++ libstdc++-devel

# 安装g++
yum -y install gcc-c++ libstdc++-devel

# 安装PCRE库的安装
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
make
make install

# 安装zlib库
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

# 安装openssl
yum -y install openssl openssl-devel

# 安装nginx
cd /usr/local/src
# wget http://nginx.org/download/nginx-1.1.10.tar.gz
# tar -zxvf nginx-1.1.10.tar.gz
wget http://nginx.org/download/nginx-1.15.3.tar.gz
tar -zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
./configure
make
make install

安装参考

https://www.cnblogs.com/wyd168/p/6636529.html

命令

启动

1
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

重启

1
/usr/local/nginx/sbin/nginx -s reload

配置校验

1
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

停止

1
2
3
4
5
6
# 杀进程
ps aux|grep nginx
kill -9 UID

# 命令
/usr/local/nginx/sbin/nginx -s stop

其他命令

1
2
3
4
5
# 查看版本号
/usr/local/nginx/sbin/nginx -v

# 查看nginx信息
/usr/local/nginx/sbin/nginx -V

Openssl

1
2
3
4
5
# 版本查看
openssl version -a

# 连接
openssl s_client -connect 127.0.0.1:443

https

需要开放443端口

证书配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 找到/use/local/nginx/conf/nginx.conf
# 在最后粘贴,且修改证书文件

server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/214982244830351.pem;
ssl_certificate_key cert/214982244830351.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}

unknow directive “ssl”

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash

# 切换到nginx源码目录安装ssl
cd /usr/local/src/nginx-1.15.3
# 配置ssl
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 编译
make
# 备份nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# 新的覆盖
cp objs/nginx /usr/local/nginx/sbin/nginx

http跳转https

1
2
3
4
5
6
server
{
listen 80;
server_name xxx.xxx.com;
return 301 https://xxx.xxx.com$request_uri;
}

其它

默认html目录

1
/usr/local/nginx/html