php - 从 nginx 中的不同位置提供 php 文件

标签 php configuration nginx

我的主要网站和 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 questionNginx 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/

相关文章:

php - 在公开 ID 上发送用户/通过帖子

PHP PDO 异常 : could not find driver

php - 有什么方法可以识别 PHP 中的 F5 刷新?

c# - C# Windows 应用程序中基于许可证的配置

nginx - 用于ARM32(Raspberry Pi)的Nginx Ingress Controller Docker镜像

nginx - 拒绝 nginx 端口 80 上的某些子域

php - IIS 上的 MSSQL 和 PHP 5.3.5 之间的连接不起作用

dictionary - Golang 映射 YAML 对象

angular - 如何将配置参数传递给 Angular 库?

types - 为什么一些像 nginx 和 pcap 这样的开源项目使用自己的 'nginx_uint_t' 和 'bpf_u_int32' 而不是内置类型 'unsigned int'