简体   繁体   English

重定向错误(在 certbot 更新/nginx 之后)

[英]Redirection error (after certbot renewal / nginx)

This configuration for my webserver works partly (actual Ubuntu).我的网络服务器的此配置部分有效(实际的 Ubuntu)。 If the newest Firefox uses the site with a smartphone, it results in a redirection error.如果最新的 Firefox 通过智能手机使用该站点,则会导致重定向错误。 Some other browsers may work, but not reliable.其他一些浏览器可能工作,但不可靠。 I tried to delete the browser cache and restarted/reloaded the nginx-server.我试图删除浏览器缓存并重新启动/重新加载 nginx 服务器。 Is there an error in the NGINX-config? NGINX-config 是否有错误? The problem first occurred, when I renewed the SSL certs with certbot.当我用 certbot 更新 SSL 证书时,问题首先出现。 Thank you!谢谢!

    server {
        listen 443 ssl;
        listen [::]:443 ssl;
    
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;    
    
        server_name sozcafe.de;     
        
        location / {
            root /var/www/html;
            index index.php;
            try_files $uri $uri/ @rewrite;
        }
        
        location @rewrite {
            rewrite ^/(forum/|chat/|cms/|wcf/|calendar/|filebase/|blog/|gallery/)?([^.]+)$ /$1index.php?$2 last;
        }
        ssl_certificate /etc/letsencrypt/live/sozcafe.de/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/sozcafe.de/privkey.pem; # managed by Certbot
        
        #ssl_certificate /etc/letsencrypt/live/www.coffeecat.de/cert.pem;
        #ssl_certificate_key /etc/letsencrypt/live/www.coffeecat.de/privkey.pem;
        
        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
            root /var/www/html;
            index index.php;
            include snippets/fastcgi-php.conf;  
        
            
            
        #
        #   # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #   # With php-cgi (or other tcp sockets):
        #   fastcgi_pass 127.0.0.1:9000;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #   deny all;
        #}
    
    
    }
    
    server {
        
        server_name sozcafe.de www.sozcafe.de;
        return 301 https://$server_name$request_uri;
        
    
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/sozcafe.de/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/sozcafe.de/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
    
    
    }
    
    server {
        if ($host = www.sozcafe.de) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        if ($host = sozcafe.de) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        listen 80;
        listen [::]:80;
        
        server_name sozcafe.de www.sozcafe.de;
        return 404; # managed by Certbot
    
    }

Looking carefully in your config file you can figure out that you are listening for the same port ( 443 ), the same server name ( sozcafe.de ) in two of your server blocks, the first and second one to be more specific.仔细查看您的配置文件,您可以发现您正在监听相同的端口 ( 443 )、相同的服务器名称 ( sozcafe.de ) 在您的两个服务器块中,第一个和第二个更具体。 Having the statement return 301 https://$server_name$request_uri in the second server block of your config causes an effect of "infinite loop" because nginx always redirects to this server block each time you access to your domain.让语句在配置的第二个服务器块中return 301 https://$server_name$request_uri会导致“无限循环”的效果,因为每次访问域时nginx总是重定向到此服务器块。

I suspect Certbot added one of those when you ran it.我怀疑 Certbot 在您运行时添加了其中一个。

You can solve it by deleting sozcafe.de in your second server block to redirect only the www domain instead the target domain itself.您可以通过删除第二个服务器块中的sozcafe.de来仅重定向www域而不是目标域本身来解决它。

    server {
        
        # server_name sozcafe.de www.sozcafe.de;
        server_name www.sozcafe.de;
        return 301 https://$server_name$request_uri;
        
    
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/sozcafe.de/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/sozcafe.de/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
    
    
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM