安装 安装依赖 1 2 3 4 yum install gcc; yum install pcre-devel; yum install zlib zlib-devel; yum install openssl openssl-devel;
下载最新稳定版并解压 1 2 wget http://nginx.org/download/nginx-1.20.2.tar.gz tar -zxvf nginx-1.20.2.tar.gz
编译 安装 1 2 3 4 5 cd nginx-1.20.2/ # 生成makefile,设置安装目录并配置ssl模块./configure --prefix=/home/soft/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-stream # 编译安装make && make install
启动 停止 1 2 3 4 5 6 7 8 9 10 # 启动/home/soft/nginx/sbin/nginx # 停止/home/soft/nginx/sbin/nginx -s stop # 待任务执行完毕再关闭/home/soft/nginx/sbin/nginx -s quit # 配置文件修改重载/home/soft/nginx/sbin/nginx -s reload # 杀掉进程,强制关闭pkill -9 nginx
配置https,域名统一跳转至www域名 修改nginx配置文件路径/home/soft/nginx/conf/nginx.conf
1 vim /home/soft/nginx/conf/nginx.conf
笔者配置如下,将80和443下域名全部301永久重定向到https://blog.shofcy.cn
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 server { listen 443; #监听443端口(https默认端口) server_name blog.shofcy.cn; add_header Strict-Transport-Security "max-age=31536000"; return 301 https://blog.shofcy.cn$request_uri; } server { listen 443 default_server ssl; #监听443端口(https默认端口) server_name blog.shofcy.cn; add_header Strict-Transport-Security "max-age=31536000"; ssl_certificate /home/soft/nginx/cert/blog.shofcy.cn.pem; #填写你的证书所在的位置 ssl_certificate_key /home/soft/nginx/cert/blog.shofcy.cn.key; #填写你的key所在的位置 ssl_session_timeout 5m; ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256::!MD5; ssl_protocols TLSv1.3 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; # 反向代理本地8080端口服务 location / { proxy_pass http://127.0.0.1:8080; } } server { listen 80; server_name blog.shofcy.cn; return 301 https://blog.shofcy.cn$request_uri; }