2016-05-22 83 views
2

我想激活我wordpress安裝上的漂亮鏈接,但沒有成功。我改變了這個文件/etc/nginx/conf.d/default.confNGINX for Wordpress上的漂亮鏈接 - CentOS 7

我試過如下:

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; 
     } 
    } 

你能幫助我嗎?

非常感謝。

+1

'try_files $ URI $ URI//index.php?$ args;' – Arcesilas

+2

另外:https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ – Arcesilas

+0

有你讀過關於使用nginx的WordPress文檔?https://codex.wordpress.org/Nginx –

回答

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

+0

薩克,感謝您的幫助。但這不工作:( 這讓我瘋了。知道該怎麼做,我知道它看起來像我做錯了什麼,但我正在關注每一個步驟,這個東西是行不通的。 – GOKULUFFYZORO

0

這是一個有點晚了,

嘗試

location/{ 
    try_files $uri $uri/ /index.php?q=$uri$args; 
} 
相關問題