【发布时间】:2014-08-11 05:59:32
【问题描述】:
我以前从未使用过 Nginx,但我想将它作为一个实验来尝试,但我在尝试在 Wordpress 中设置漂亮的 URL 时迷失了方向。
但是,如果我将永久链接设置为查询字符串以外的任何内容,则会导致在尝试转到重写的 URL 时抛出 404。
这是我的 Nginx conf,有人可以告诉我我做错了什么吗?我在类似问题上尝试了多个答案,但没有任何运气。
Ngix 会议
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,这就是发生错误的地方。
提前致谢。 马特
【问题讨论】:
标签: php wordpress nginx url-rewriting