【问题标题】:Pretty Permlinks on NGINX for Wordpress - CentOS 7NGINX for Wordpress 上的漂亮永久链接 - CentOS 7
【发布时间】:2016-05-22 22:24:27
【问题描述】:

我正在尝试在我的 wordpress 安装中激活漂亮的永久链接,但没有成功。我正在更改此文件 /etc/nginx/conf.d/default.conf

我尝试了以下方法:

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

server {
if ($host ~* ^myhost\.com$) {
    rewrite ^(.*) http://www.myhost.com$1 permanent;
    break;
} 

location / {
        try_files $uri $uri/ /index.php?q=$request_uri;
}

但是这些都不起作用:(。这是我的完整文件:

 server {
    listen       80;
    server_name  example.com;
    return       301 http://www.example.com$request_uri;

}


    server {
    listen       80;
    server_name  www.example.com;

     note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
    root   /usr/share/nginx/html;
           index  index.php index.html index.htm;
           try_files $uri $uri/ /index.php?$args;      

    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;  
      }
    }

你能帮帮我吗?

非常感谢。

【问题讨论】:

标签: php wordpress nginx centos7


【解决方案1】:
server {
    listen       80;
    server_name  your-domain.com www.your-domain.com;

    root   /usr/share/nginx/html/your-wp-root-dir;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php?q=$request_uri;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

更新default.conf文件后不要忘记重启nginx服务器(sudo /etc/init.d/nginx restart

【讨论】:

  • 萨克,感谢您的帮助。但这不起作用:(这让我发疯。我不知道该怎么做。我知道看起来我做错了什么,但我正在遵循每一步,这件事不起作用。
【解决方案2】:

有点晚了,

试试

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

【讨论】:

    猜你喜欢
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 2016-12-28
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多