Nginx

PHP 上的 Nginx 重定向錯誤太多

  • July 11, 2021

我有 2 個在不同埠上執行的節點應用程序和一個 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


}

/sourcebans/從to刪除不適當的 301 重定向/sourcebans

引用自:https://serverfault.com/questions/1069251