我在NGINX服务器上遇到一个奇怪的问题。
如法典中所述,我将wordpress从我的根目录移到了/ blog /子目录。
它成功显示了博客索引,但是如果我想显示其他内容,例如特定的帖子或存档页面,它将提供根index.php
甚至不存在的URL也用作根index.php
如果删除根index.php,它将返回404错误。
也许是由于我的nginx和fastcgi设置所致,但是我真的没有头绪:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm;
client_max_body_size 10M;
# Make site accessible from http://localhost/
server_name
set $no_cache 0;
if ($request_method = POST){set $no_cache 1;}
if ($query_string != ""){set $no_cache 1;}
if ($http_cookie = "PHPSESSID"){set $no_cache 1;}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {set $no_cache 1;}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in"){set $no_cache 1;}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_cache microcache;
fastcgi_cache_key $scheme$host$request_uri$request_method;
fastcgi_cache_valid 200 301 302 30s;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_pass_header Set-Cookie;
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
编辑:更新了整个服务器块
try_files语句将所有不存在的文件发送到Web根目录中的index.php。在配置中添加一个专门用于您博客的第二个位置:
location /blog {
try_files $uri $uri/ /blog/index.php;
}
try_files的工作方式如下:
按指定顺序检查文件是否存在,并使用找到的第一个文件进行请求处理;该处理是在当前上下文中执行的。文件的路径是根据根和别名指令从file参数构造的。可以通过在名称末尾指定斜杠来检查目录是否存在,例如“ $ uri /”。如果未找到任何文件,则将进行内部重定向到最后一个参数中指定的uri。例如:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句