1.需求
http://www.baidu.com:5000
https://www.baidu.com:5000
請(qǐng)求自定義端口的http 跟https,都一樣的頁(yè)面文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-539129.html
2.nginx配置
vim /opt/lucky/nginx/conf/vhosts/baidu.conf文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-539129.html
upstream gatewayservice {
server 127.0.0.1:9000 weight=1; #反代tomcat服務(wù)
}
server {
listen 5000 ssl; #自定義的監(jiān)聽(tīng)端口
server_name www.baidu.com; #改成你的域名
ssl_certificate /opt/lucky/nginx/conf/keys/tgchat111/server.crt;
ssl_certificate_key /opt/lucky/nginx/conf/keys/tgchat111/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
set $redirectMode gatewayservice;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
if ($scheme = 'https') {
proxy_pass http://gatewayservice;
break;
}
try_files $uri $uri/ @http_to_https;
index index.html index.htm;
}
location @http_to_https {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gatewayservice;
}
error_page 497 = @http_to_https;
error_page 405 =200 $uri;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
到了這里,關(guān)于nginx的同一個(gè)端口配置支持http與https協(xié)議的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!