52错误:www在Edge / Chrome / Mobile中未重定向:`ERR_EMPTY_RESPONSE`

问题描述 投票:0回答:1

更新:确定罪魁祸首:

在最后一行的第4行,应删除ssl。不知道为什么。如果有人可以解释原因,请添加您的答案。谢谢!

目标系统信息:

  • 我正在使用Debian 10,Buster,使用的是nginx 1.42,certbot Latest-stable和php 7.3。
  • [在同一个IP地址和端口上有两个域名;因此,example.com和example1.com(在下面看到example.com.conf)。
  • 一切都是原始的,即开即用:nginx.conf是未更改,php的配置文件是未更改除了LEMP和Certbot,未安装任何东西

有害行为:

WolfPack'08@NV89501:/# curl www.example.com
curl: (52) Empty reply from server
WolfPack'08@NV89501:/# curl http://example.com
curl: (52) Empty reply from server
WolfPack'08@NV89501:/# curl http://www.example.com
curl: (52) Empty reply from server
WolfPack'08@NV89501:/# curl https://www.example.com
WolfPack'08@NV89501:/# curl https://example.com
<!DOCTYPE html>

最佳尝试,特定于站点的配置:请参见注释(###):

server {
        set $base /var/www/example.com;
        root $base/public;
        access_log /var/log/nginx/example.com/access.log;
        error_log /var/log/nginx/example.com/error.log;

        index index.php;
        server_name www.example.com example.com;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

    listen [::]:443 ssl http2; 
    listen 443 ssl http2; 
    server_name www.example.com example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

### SECTION INTENDED TO HANDLE WWW-to-NON_WWW REDIRECTS: ###
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    }
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    }
        listen [::]:80;
        listen 80 ssl;  ### REMOVE SSL HERE TO FIX. ###
        server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

我尝试过的其他东西:

  • 将301放在其他位置(例如,顶部,在index.php下;)。
  • 使用302而不是301。
  • 正在删除listen 80 ssl;
  • 使用return 301 https://$host$request_uri;而不是example.com。>>
  • 从启用站点的其他符号链接中删除。
  • 当然,我每次都重新启动Nginx

我没有收到错误

更新:罪魁祸首:在第四行至最后一行,应删除ssl。不知道为什么。如果有人可以解释原因,请添加您的答案。谢谢!目标系统信息:我在Debian 10上,...

nginx redirect http-status-code-301 http-status-code-302 no-www
1个回答
0
投票

尝试以下配置

© www.soinside.com 2019 - 2024. All rights reserved.