简体   繁体   English

NginX:别名和位置

[英]NginX : alias and location

Hello StackOverflowers, 您好StackOverflowers,

I'm struggling for more than a day on this problem. 我在这个问题上奋斗了一天多。 I have 2 sites, one is the application and one is the front wordpress. 我有2个站点,一个是应用程序,一个是前台wordpress。

The files are as follow : 文件如下:

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

The problem is that I'm moving from apache to nginx and I can't change the URLs. 问题是我正在从apache迁移到nginx,并且无法更改URL。 The mapping must be like that : 映射必须是这样的:

I failed to configure NginX to do that. 我无法配置NginX来做到这一点。 I dont know why, this configuration makes me headash ! 我不知道为什么,这种配置让我头晕! I still don't get the logic of NginX. 我仍然不了解NginX的逻辑。 Here is the important part of my conf : 这是我的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;
    }
}

Can you point me out where is my mistake ? 你能指出我的错误在哪里吗?

Thank you ! 谢谢 !

I think the follow will works: 我认为以下做法会有效:

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
  }
}

Your first location doesn't work because alias wants a directory. 您的第一个位置不起作用,因为alias一个目录。

And maybe you would check nginx 's logfiles. 也许您会检查nginx的日志文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM