我无意中将 Wordpress 安装到了我的 Ubuntu nginx 服务器的根目录中。如何将此安装从根目录移动到名为 /blog 的子目录?例如 mysite.com/blog
我现在拥有的:
server {
listen 80;
server_name mysite.com;
root /srv/www/wordpress;
index index.php index.html index.htm;
include conf.d/wp/restrictions.conf;
# Additional rules go here.
include conf.d/wp/wordpress.conf;
}
以下是conf.d/wp/wordpress.conf
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
index index.html index.htm index.php;
}
location /blog {
index index.html index.htm index.php;
try_files $uri $uri/ /blog/index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Uncomment the line below for the W3 total caching plugin (if used).
#include conf.d/wp/wordpress-w3-total-cache.conf;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
尽管添加了:
location /blog {
index index.html index.htm index.php;
try_files $uri $uri/ /blog/index.php?$args;
}
仅供参考 Wordpress 仍然位于/srv/www/wordpress
...它仍然不起作用,这让我怀疑我是否真的明白自己在做什么!
任何帮助我都感激不尽。谢谢。
答案1
通过移动/srv/www/wordpress
到子目录解决了这个问题。最终的 URI 是:/srv/www/html/blog
Wordpress 文件位于/srv/www/html/blog
然后服务器块将改为这样:root /srv/www/html;
# Redirects users from root to /blog
location = / {
return 301 http://example.com/blog;
}
location /blog {
# index index.html index.htm index.php;
try_files $uri $uri/ /blog/index.php?$args;
}