通过 Ngnix 配置解决 WordPress 固定链接 404 问题

近期博客迁移到 racknerd vps,迁移后固定链接伪静态访问 404。排查后原因是 Nginx 配置问题,期间还遇到跳转 https: 无限死循环的问题,故记录正确完整 Nginx配置。代码语言:javascript代码运行次

通过 Ngnix 配置解决 WordPress 固定链接 404 问题

近期博客迁移到 racknerd vps,迁移后固定链接伪静态访问 404。

排查后原因是 Nginx 配置问题,期间还遇到跳转 https:// 无限死循环的问题,故记录正确完整 Nginx 配置。

代码语言:javascript代码运行次数:0运行复制
server {
        listen 80;
        listen [::]:80;
        root /var/www/html; #你的 wordpress 目录
        #server_name  xuanyuan.me; 
        #上面这个注释不能去掉,否则两个命名空间会导致https跳转无限死循环
        index index.php index.html index.htm;
        location / {
                try_files $uri $uri/ =404;
        }
        rewrite ^(.*) https://$host$1 permanent; #跳转 https
}

server {
        listen 443      ssl http2;
        listen [::]:443 ssl http2;
        root /var/www/html;
        server_name  xuanyuan.me;
        index index.php index.html index.htm;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_certificate     /etc/nginx/ssl/xxx.pem;     #你的证书目录
        ssl_certificate_key /etc/nginx/ssl/xxx.key;     #你的证书目录

        add_header Referrer-Policy           "no-referrer"   always;
        add_header X-Content-Type-Options    "nosniff"       always;
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ~ /\. {
                deny all;
        }

        location ~* /(?:uploads|files)/.*\.php$ {
                deny all;
        }

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

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

        location /blog { #注意:此处/blog为wordpress目录
                try_files $uri $uri/ /blog/index.php?$args; #注意:此处/blog为wordpress目录
        }

        location ~ \.php$ {
                include fastcgi.conf;
                fastcgi_pass   unix:/run/php/php7.4-fpm.sock; #修改为你的php版本
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }

        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。如有侵权请联系 cloudcommunity@tencent 删除wordpress迁移fastcgi配置php

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755055714a5233910.html

相关推荐

  • 通过 Ngnix 配置解决 WordPress 固定链接 404 问题

    近期博客迁移到 racknerd vps,迁移后固定链接伪静态访问 404。排查后原因是 Nginx 配置问题,期间还遇到跳转 https: 无限死循环的问题,故记录正确完整 Nginx配置。代码语言:javascript代码运行次

    1月前
    210

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信