Nginx
如何找到此錯誤循環的 301 重定向在哪裡?
我得到重定向循環/無限鏈,我無法弄清楚。我對程式和伺服器非常陌生,所以請幫助非常環保的人!這是我到目前為止所擁有的:
.htaccess
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
路線
Route::get('/', [ 'as' => 'get.site', 'uses' => 'SiteController@getHome' ]);
控制器
public function getHome() { $this->model['title'] = 'Home Page'; $this->model['description'] = 'Welcome to my home Page'; return $this->renderView('home'); }
這是我的 nginx 文件:
# FORGE CONFIG (DOT NOT REMOVE!) include forge-conf/example.com/before/*; server_tokens off; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; add_header X-XSS-Protection "1; mode=block"; add_header Referrer-Policy "no-referrer-when-downgrade"; add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"; server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.com; root /home/forge/example.com; # FORGE SSL (DO NOT REMOVE!) ssl_certificate /etc/nginx/ssl/example.com/server.cr; ssl_certificate_key /etc/nginx/ssl/example.com/server.key; ssl_session_cache shared:SSL:50m; ssl_session_timeout 1d; ssl_session_tickets off; ssl_dhparam /etc/nginx/dhparams.pem; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; resolver 8.8.8.8 8.8.4.4 valid=300s; ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/nginx/ssl/example.com/188983/server.crt; add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload;"; index index.html index.htm index.php; charset utf-8; #SET REAL IP set_real_ip_from 127.0.0.1; set_real_ip_from 10.0.1.174; real_ip_header X-Forwarded-For; real_ip_recursive on; # FORGE CONFIG (DOT NOT REMOVE!) include forge-conf/example.com/server/*; location / { try_files $uri $uri/ /index.php$is_args$args; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log off; error_log /var/log/nginx/example.com-error.log error; #error_page 404 /index.php; location ~ \.php$ { fastcgi_intercept_errors on; #try_files $uri =404; try_files $uri /index.php =404; fastcgi_index index.php; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } # FORGE CONFIG (DOT NOT REMOVE!) include forge-conf/example.com/after/*;
http://example.com的響應標頭:
URL: http://example.com http/1.1 301 moved permanently server: nginx/1.11.9 date: Sun, 09 Jul 2017 23:53:40 GMT content-type: text/html content-length: 185 connection: keep-alive location: https://example.com/ Redirecting URL: https://example.com/ http/1.1 301 moved permanently server: nginx/1.11.9 date: Sun, 09 Jul 2017 23:53:41 GMT content-type: text/html content-length: 178 connection: keep-alive location: http://example.com/ x-frame-options: SAMEORIGIN x-content-type-options: nosniff x-xss-protection: 1; mode=block referrer-policy: no-referrer-when-downgrade content-security-policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'
https://example.com的響應標頭
URL: https://example.com http/1.1 301 moved permanently server: nginx/1.11.9 date: Sun, 09 Jul 2017 23:56:58 GMT content-type: text/html content-length: 178 connection: keep-alive location: http://example.com/ x-frame-options: SAMEORIGIN x-content-type-options: nosniff x-xss-protection: 1; mode=block referrer-policy: no-referrer-when-downgrade content-security-policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none' Redirecting URL: http://example.com/ http/1.1 301 moved permanently server: nginx/1.11.9 date: Sun, 09 Jul 2017 23:56:58 GMT content-type: text/html content-length: 185 connection: keep-alive location: https://example.com/
你的問題部分是這個:
server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; return 301 $scheme://$host$request_uri; }
方案變數包含用於連接到此伺服器的方案。由於此伺服器塊僅偵聽埠 80,因此方案將始終為
http
. 這意味著這個塊總是重定向到它自己。要解決此問題,只需更改$scheme
為https
:server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; return 301 https://$host$request_uri; }