1.需求
http://www.baidu.com:5000
https://www.baidu.com:5000
请求自定义端口的http 跟https,都一样的页面文章来源:https://www.toymoban.com/news/detail-539129.html
2.nginx配置
vim /opt/lucky/nginx/conf/vhosts/baidu.conf文章来源地址https://www.toymoban.com/news/detail-539129.html
upstream gatewayservice {
server 127.0.0.1:9000 weight=1; #反代tomcat服务
}
server {
listen 5000 ssl; #自定义的监听端口
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 {
}
}
到了这里,关于nginx的同一个端口配置支持http与https协议的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!