NGINX for Wordpress上的漂亮Permlink - CentOS 7

时间:2016-05-22 22:24:28

标签: php wordpress nginx centos7

我试图在我的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;  
      }
    }

你能帮我吗?

非常感谢。

2 个答案:

答案 0 :(得分: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;
    }
}

更新nginx文件(default.conf

后,请不要忘记重新启动sudo /etc/init.d/nginx restart服务器

答案 1 :(得分:0)

有点晚了,

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