我们用nginx为后端服务提供HTTPS支持,都会配置证书,并且会有一个大家比较熟悉的配置:
rewrite ^(.*)$ https://$host$1 permanent;
这个重定向。
因为这个配置,所有的前端请求都会被443端口处理,
所以nginx.conf配置文件里server 80 端口的location配置都会失效,也就是下面的配置
本来我映射到8020的location配置写在这里的,在网上找了好半天其他方案,都一直不行,
真是欲哭无泪,后来找了亮仔(专业运维大神),一眼看到症结所在,佩服,牛逼plus。
把跳转到location配置到server443端口就可以了,因为HTTPS的前端请求已经被rewrite到这里进行监听处理。
配置如下:
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /soft/cert/https/full_chain.pem;
ssl_certificate_key /soft/cert/https/private.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
location /app {
proxy_http_version 1.1;
proxy_read_timeout 30s;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
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";
proxy_pass http://127.0.0.1:8020/passerdiary/;