2017-02-20 93 views
0

我想从apache迁移我的个人sterver到nginx,但我不能得到的位置工作。Nginx的工作与类似Apache的位置

我的服务器有几个应用程序,在某些/某事从根部,像url.com/git url.com/mediaWiki avaliable,url.com/vnstat url.com/redmine

在Apache中一个有一堆为每个应用程序配置文件:

redmine.conf

<Location "/redmine"> 
    Options none 
    Require all granted 

    PassengerEnabled On 
    RailsBaseURI /redmine 
    RailsEnv production 
</Location> 

vnstat_php.conf

Alias /vnstat /var/www/vnstat_php 

<Directory /var/www/vnstat_php> 
     DirectoryIndex index.php 
     Require all granted 
</Directory> 

我正试图在nginx上复制这个,但我迄今为止最好的尝试最终得到了一个奇怪的url。我只有管理事主ngix配置文件的工作文字:

server { 
    listen  8123 default_server; 
    listen  [::]:8123 default_server; 
    server_name _; 
    root   /var/www/html; 

    location/{ 
    } 

    location /vnstat/ { 
     root /var/www/vnstat_php/; 
     index index.php; 
    } 
} 

根页好的工作,但/ vnstat链接送我去

2017/02/20 11:37:19 [error] 27538#0: *1 "/var/www/vnstat_php/vnstat/index.php" is not found (2: No such file or directory), client: 177.92.59.216, server: _, request: "GET /vnstat/ HTTP/1.1", host: "url.com:8123" 

它正在寻找一个vnstat/var/www/vnstat_php /目录中,而不是以root身份使用它。任何人都可以将我指向正确的方向吗?

+0

你需要'alias'不' root'。或许[像这样](http://stackoverflow.com/questions/42176020/nginx-yii2-configuration-in-different-folders/42203734#42203734)。 –

回答

0

截至http://nginx.org/en/docs/http/ngx_http_core_module.html#root

描述文件的路径,将通过仅仅增加一个URI到根指令的值构成。如果必须修改URI,则应使用别名指令。

你应该使用别名这种情况下:

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

location /vnstat/ { 
    alias /var/www/vnstat_php/; 
} 

但使用PHP与nginx的你应该考虑FastCGI的工作:https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

+0

仍然看错了地方 open()“/ var/www/html/vnstat”失败(2:没有这样的文件或目录),客户端:177.92.59.216,服务器:_,请求:“GET/vnstat HTTP/1.1“,主机:”url.com:8123“,引用者:”http://url.com:8123/frame.html“ – Techmago