【问题标题】:NginX : alias and locationNginX:别名和位置
【发布时间】:2015-07-24 19:35:51
【问题描述】:

你好 StackOverflowers,

我在这个问题上挣扎了一天多。我有2个站点,一个是应用程序,一个是前端wordpress。

文件如下:

  • 应用程序:C:/Users/NICOLAS/Documents/www/index.php
  • Wordpress:C:/Users/NICOLAS/Documents/www/wordpress/index.php

问题是我正在从 apache 迁移到 nginx,我无法更改 URL。映射必须是这样的:

我未能配置 NginX 来执行此操作。不知道为什么,这个配置让我头疼!我仍然不明白 NginX 的逻辑。这是我的 conf 的重要部分:

root C:\Users\NICOLAS\Documents\www;
location ~ ^/v1/(.+\.php.*)$ {
    alias "C:/Users/NICOLAS/Documents/www/$1";
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include        fastcgi_params;
    }
}

location ~ / {
    alias C:/Users/NICOLAS/Documents/www/wordpress/;
    location ~ \.php$ {fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

你能指出我的错误在哪里吗?

谢谢!

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    我认为以下方法可行:

    location /v1 {
      alias "C:/Users/NICOLAS/Documents/www/";
      location ~ \.php$ {
        # php-specific part
      }
    
    location / {
      alias C:/Users/NICOLAS/Documents/www/wordpress/;
      location ~ \.php$ {
        # php-specific part
      }
    }
    

    您的第一个位置不起作用,因为alias 想要一个目录。

    也许你会检查nginx的日志文件。

    【讨论】:

    • 您好,谢谢您的回答。但是 /v1 位置不起作用,因为在查看调试 nginx 日志文件时,nginx 尝试为C:/Users/NICOLAS/Documents/www/v1/index.php 提供服务,这不是我所期望的。我希望它服务C:/Users/NICOLAS/Documents/www/index.php
    猜你喜欢
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 2010-12-21
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    • 2015-10-17
    相关资源
    最近更新 更多