[英]Nginx, Wordpress 3.9.2 and rewrites result in 404
我以前從未使用過Nginx,但我想嘗試一下它作為實驗,卻迷失了嘗試在Wordpress中設置漂亮的URL的方法。
但是,如果我將永久鏈接設置為查詢字符串以外的任何其他內容,則嘗試轉到重寫的URL時會引發404。
這是我的Nginx conf,有人可以讓我知道我做錯了嗎? 我已經嘗試過類似問題的多個答案,但沒有任何運氣。
Ngix Conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name site.co.uk;
client_max_body_size 200M;
location / {
index index.php index.html index.htm
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name www.site.co.uk;
return 301 $scheme://site.co.uk$request_uri;
}
因此,例如,如果我嘗試轉到site.co.uk/my-account,這就是發生錯誤的地方。
提前致謝。 馬特
我設法通過將以下規則添加到我的nginx配置中來修復它
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
從以下網站Farinspace-Wordpress nginx重寫規則
希望這可以幫助其他與我有相同問題的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.