Nginx 未升级到 Https

标签 nginx https server

我已经配置nginx将请求升级为https

server {
        listen xxx.xxx.xxx.xxx:80;
        listen xxx.xxx.xxx.xxx:443 ssl;

        server_name example.com www.example.com

        access_log  /var/log/nginx/www.example.com_access.log;
        error_log /var/log/nginx/www.example.com_error.log warn;

        ssl_certificate /etc/nginx/ssl/certificates/www.example.com.crt;
        ssl_certificate_key  /etc/nginx/ssl/certificates/www.example.com.key;

    location / {
        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  X-Forwarded-Proto $scheme;
        #https://www.scalescale.com/tips/nginx/504-gateway-time-out-using-nginx/
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
        proxy_pass https://xxx.xxx.xxx.xxx:8443/;
        index  index.html ;
    }
}

但配置并未将请求升级为 https。

最佳答案

server {
    listen       80;
    server_name  example.com www.example.com;
    return       301 https://$host$request_uri;
}

server {
    listen       443 ssl;
    server_name  example.com www.example.com;
    ...
}

如果您不需要加密后端和 nginx 实例之间的流量(如果它们在同一服务器上工作,那么您肯定不需要它),请删除 proxy_pass 指令以获得一些性能优势。

关于Nginx 未升级到 Https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62278887/

相关文章:

php - 为 Wordpress 上的高流量网站推荐的 Nginx 配置

session - Nginx 强制 SSL (https) 与 cookie 转发

java - 来自 Thawte 的 Glassfish 4.0 SSL 证书

Java:如何在没有异常的情况下停止服务器(关闭套接字)?

angularjs - 在angularJS前端出现CORS错误

nginx - docker运行启动服务

https - 不安全登录被阻止 : You can't get an access token or log in to this app from an insecure page. 尝试将页面重新加载为 https://

python - Windows Server 2008/IIS 7 上 Mercurial 1.9.2 的 HTTPS 给我 Errno 10054

java - 用于 json 的日期格式

javascript - 在新页面中动态生成 HTML(服务器端)