PHP 上的 Nginx 重定向错误过多

PHP 上的 Nginx 重定向错误过多

我有两个在不同端口上运行的节点应用程序和一个 PHP 应用程序。当我访问节点应用程序时,我没有收到任何错误,但如果我尝试转到 PHP 应用程序(在 /sourcebans 上),我会收到This site redirected you too many times如何修复此问题?

我的配置

server {
  server_name 108.61.142.108;
  return 301 https://hwgaming.tf$request_uri;
}

#server {
#  server_name www.hwgaming.tf;
#  return 301 https://hwgaming.tf$request_uri;
#}

server {
  server_name hwgaming.tf;
#       rewrite ^/(.*)/$ /$1 permanent;
        root /var/www/html/hwgaming/;
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;


        location / {
#                First attempt to serve request as file, then
#                as directory, then fall back to displaying a 404.
                proxy_pass http://localhost:9000;
                proxy_http_version 1.1;
                proxy_connect_timeout 300;
                proxy_read_timeout 300;
                proxy_send_timeout 300;
                send_timeout 300;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location /sourcebans/ {
                return 301 https://hwgaming.tf/sourcebans;
        }

        location /guardbans/ {
                return 301 https://hwgaming.tf/guardbans;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/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;
        }

        location /guardbans {
                proxy_pass http://localhost:3000/;
                proxy_http_version 1.1;
                proxy_connect_timeout 300;
                proxy_read_timeout 300;
                proxy_send_timeout 300;
                send_timeout 300;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location /api {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
                proxy_pass http://localhost:3001/api;
        }

        location /_next/ {
                alias /var/www/html/hwgaming/guardbans/.next/;
        }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/hwgaming.tf/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/hwgaming.tf/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.hwgaming.tf) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name www.hwgaming.tf;
    return 404; # managed by Certbot


}


server {
    if ($host = hwgaming.tf) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  server_name hwgaming.tf;
    listen 80;
    return 404; # managed by Certbot


}

答案1

/sourcebans/从到删除不适当的 301 重定向/sourcebans

相关内容