Nginx ERR_TOO_MANY_REDIRECTS 透過調整 WordPress 永久連結 | 301 錯誤 Ubuntu 18.04

Nginx ERR_TOO_MANY_REDIRECTS 透過調整 WordPress 永久連結 | 301 錯誤 Ubuntu 18.04
  • 作業系統:Ubuntu 18.04.5 LTS(有我自己的VPS)
  • 網路伺服器:Nginx/1.18.0
  • MySQL:適用於 x86_64 上 Linux 的 mysql 版本 8.0.22(MySQL 社群伺服器 - GPL)
  • WordPress:5.6

當我改變固定連結WordPress 中的選項(螢幕截圖:/wp-admin/options-permalink.php)從預設值(?p=123) 到/%帖子名%/(頁面上的最後一個選項)我收到以下錯誤:“ERR_TOO_MANY_REDIRECTS”帶狀態碼301 限主頁 (所以直接 example.com),所有其他頁面都工作正常,甚至新的永久連結選項也工作正常,因此可以透過以下方式存取預設部落格:/你好世界/直接地。

知道為什麼嗎?這是我的伺服器完成後要做的最後一件事,在這個小錯誤上花費的時間比其他事情都多,哈哈。注意:我已經禁用了所有插件,但 nginx 快取除外,我用它來清除伺服器端快取。我還以隱身方式訪問該網站。

我按照這個教學進行操作:SpinUp WP(我做了所有事情,直到CH6)。我的 NGINX 設定如下:

NGINX 設定檔(出於隱私原因,我已將用戶名更改為 omar):

user omar;
worker_processes 6;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 1024;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        keepalive_timeout 15;
        types_hash_max_size 2048;
        server_tokens off;
        client_max_body_size 64m;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;


        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 5;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Cache Settings
        ##
        fastcgi_cache_key "$scheme$request_method$host$request_uri";
        add_header Fastcgi-Cache $upstream_cache_status;


        ##
        # Security
        ##
        add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;
        add_header X-Xss-Protection "1; mode=block" always;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "origin-when-cross-origin" always;



        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        server {
            listen 80 default_server;
            listen [::]:80 default_server;
            server_name _;
            return 444;
        }
}

example.com的設定文件(出於隱私原因,我已將用戶名更改為 omar,將網域更改為 example.com):

fastcgi_cache_path /home/omar/example.com/cache levels=1:2 keys_zone=example.com:100m inactive=60m;

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

access_log /home/omar/example.com/logs/access.log;
error_log /home/omar/example.com/logs/error.log;

root /home/omar/example.com/public/;
index index.php;

set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}

# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}

if ($request_uri ~* "/(cart|checkout|my-account)/*$")
{
set $skip_cache 1;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache example.com;
fastcgi_cache_valid 60m;
}
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name www.example.com;;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

return 301 https://example.com$request_uri;
}

server {
listen 80;
listen [::]:80;

server_name example.com www.example.com;;

return 301 https://example.com$request_uri;
}

如果我需要展示更多東西,請告訴我,我會展示更多。

答案1

感謝上帝,我找到了答案。這都是因為我想成為完美主義的穆斯林,我在裡面的網址中使用了大寫字母:/wp-admin/options-general.php。所有對真主(Alhamdulillah)的讚美都透過將所有字母變成小寫來解決。按照真主的旨意(沙阿真主),它將幫助你們兄弟和非兄弟。

相關內容