2017-02-20 90 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