【问题标题】:Wordpress permalink after migrating to Nginx迁移到 Nginx 后的 Wordpress 永久链接
【发布时间】:2017-10-05 14:26:05
【问题描述】:

我的固定链接是~~/%category%~~/%postname%/~~.html~~。 我从 Apache 迁移到 Nginx。 然后我在

中添加了我的配置文件
server{
location /mydirectory/ {
    try_files $uri $uri/ /mydirectory/$uri.html;
}

但是我的浏览器继续进入 404 页面。 我尝试了删除缓存后发现的许多代码,但仍然没有成功。任何帮助将不胜感激 谢谢

我停用了所有插件,并且能够将我的永久链接更改为

/%postname%/

这是我的 my.site.com 配置(我的网站位于子目录 Vie/ 中):

server {
listen 80;
server_name my.site.com;
location ~ /(vie|\|Vie|Vie)/(.*) {
return 301 https://my.site.com/Vie;
}
return 301 https://my.site.com/Vie$request_uri;
}

 server {
    listen 443 ssl;
server_name   my.site.com;
root /var/www/my.site.com/html;
index index.php index.html;

ssl_certificate /etc/letsencrypt/live/krouus.company/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/krouus.company/privkey.pem;

 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

 ssl_prefer_server_ciphers on;
 ssl_ciphers 'DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-CAMELLIA256-SHA:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-CAMELLIA128-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256';

 ssl_session_cache shared:SSL:10m;
 ssl_session_timeout 10m;


 ssl_dhparam /etc/nginx/dhparam.pem;


add_header Strict-Transport-Security "max-age=31536000;";

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


location / {
    try_files $uri $uri/ /Vie/index.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_ignore_client_abort off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffers 4 256k;
        fastcgi_buffer_size 128k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
}
    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
            include fastcgi_params;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_param SCRIPT_FILENAME       
    $document_root$fastcgi_script_name;
}


    location ~* commun {
        deny all;
} 


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

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
    location ~ /\.ht {
    deny  all;
}
location ~ (^|/)\. {
    return 403;
}
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
        expires max;
        log_not_found off;
        ## No need to bleed constant updates. Send the all shebang in one
        ## fell swoop.
        tcp_nodelay off;
        ## Set the OS file cache.
        open_file_cache max=1000 inactive=120s;
        open_file_cache_valid 45s;
        open_file_cache_min_uses 2;
        open_file_cache_errors off;
    }
location ~* \.ini$ {
    deny all;
    return 404;
}
    error_page 404 /404.html;
       location /404.html {
       internal;
     }

    location ~* /(?:uploads|files)/.*\.(html|htm|shtml|php|js|swf|py|jsp|asp|sh|cgi)$ {
    deny all;
    }
    if ($request_method !~ ^(GET|POST|HEAD)$ ) {
  return 444;
   }

  location ~* wp-includes/theme-compat/ {
    deny all;
   }

 location ~* wp-includes/js/tinymce/langs/.*.php {
    deny all;
 }

location /wp-includes/ {
internal;
}
 location ~* .(pl|cgi|py|sh|lua|asp)$ {
     return 444;
  }
 location ~* /(wp-config.php|readme.html|license.txt|nginx.conf) {
  deny all;
  }


if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
 }

 location /xmlrpc.php {
 deny all;
 }
}

【问题讨论】:

    标签: wordpress nginx configuration http-status-code-404 permalinks


    【解决方案1】:

    试试这个。由于我也面临同样的问题,希望它对你也有用。

    location /mydirectory{
        try_files $uri $uri/ /mydirectory/index.php;
    }
    

    【讨论】:

      【解决方案2】:

      其实我解决了我的问题。我仔细阅读了我的配置并删除了

      if (!-e $request_filename) {
      rewrite ^.*$ /index.php last;
       }
      

      现在我的 Wordpress 可以工作了。

      欢呼!

      【讨论】:

        猜你喜欢
        • 2011-11-20
        • 1970-01-01
        • 2015-12-22
        • 2013-03-26
        • 1970-01-01
        • 2015-02-20
        • 2017-07-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多