nginx 公开端口并且不重定向

nginx 公开端口并且不重定向

服务器 1 - 192.168.0.1 已安装 nginx 和 apache。apache 监听端口 8000,nginx 监听端口 80。nginx 充当 TLS 终止点和负载均衡器。

服务器 2 - 192.168.0.1 apache 监听端口 80

HTTPS 运行正常。

问题是当流量指向服务器 1 时:

网页显示为http://test.net:8000并且没有重定向到 HTTPS 并且也没有在地址上公开端口http://test.net:8000

我是 nginx 新手,我该如何改进我的配置:

upstream testpool {
    least_conn;
    server 192.168.0.1:8000;
    server 192.168.0.2:80;
    }

server {

    server_name test.com test.net;

    listen 80 default_server;
    listen [::]:80 default_server;

    #redirect non http to https
    #return 404; # managed by Certbot
    #not recomended rewrite ^ https://$host$request_uri;
    return 301 https://$host$request_uri;


}

server {

    server_name test.com test.net;
    listen 443 ssl default_server;

    #ssl section, listen 443 is new way of ssl on;
    ssl_certificate /etc/letsencrypt/live/test.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
    resolver 8.8.8.8;

    proxy_pass http://testpool;
    include /etc/nginx/proxy_params;
    #return 301 https://$server_name$request_uri;

    }
}

相关内容