我的主要网站和 wordpress 位于我服务器上的不同目录中,我在该服务器上使用 nginx 作为 Web 服务器。主要网站在/home/me/www 中,Wordpress 在/home/me/wordpress 中。出于特定原因,我需要以这种方式将它们放在不同的目录中。我如何在 nginx 配置文件中指定它?我目前有以下内容但它不起作用:
location / {
root /home/me/www;
index index.php index.html index.htm;
}
location /blog {
root /home/me/wordpress;
index index.php index.html index.htm;
}
location ~ \.php$ {
set $php_root /home/me/www;
if ($request_uri ~ /blog) {
set $php_root /home/me/wordpress;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
当我尝试访问 http://mydomain/blog 时,它当前返回 HTTP 404
最佳答案
查看 this question和 Nginx Manual .
尝试将您的 blog
行更改为:
location ^~ /blog/ {
root /home/me/wordpress;
index index.php index.html index.htm;
}
关于php - 从 nginx 中的不同位置提供 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2237189/