NGINX开启HTTPS
首先在你的 nginx 目录下创建一个
.conf
文件:1
touch /etc/nginx/sites-available/test-https.conf
并填入如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21server {
listen 443 ssl;
server_name www.example.com;
index index.html;
ssl_certificate /usr/local/nginx/cert/www.example.com.pem;
ssl_certificate_key /usr/local/nginx/cert/www.example.com.key;
location / {
proxy_pass http://127.0.0.1:__YOUR_PORT__;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ^~ /api/ {
proxy_pass http://127.0.0.1:__YOUR_PORT__/;
}
}注意:第2行listen后面是
443 ssl
,莫要忘了ssl。创建软连接到
/etc/nginx/sites-available/test-https.conf
1
ln -s /etc/nginx/sites-available/test-https.conf /etc/nginx/sites-enabled/test-https.conf
将HTTPS证书上传到
/usr/local/nginx/cert/
重启NGINX服务
1
systemctl restart nginx
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 RhythmLian's Blog!
评论