2016-08-16 93 views
0

有人可以幫助我將這個Apache文件轉換爲nginx。我最喜歡的是'neptix'作爲sitename ..所以在瀏覽器中,我可以使用neptix/about-us,neptix/contact-us。注:沒有.COM本地nginx自定義url

<VirtualHost 127.0.0.1> 
    ServerName neptix 
    ServerAlias *.neptix 

    ProxyRequests Off 
    ProxyPreserveHost On 

    <Proxy *> 
     Order deny,allow 
     Allow from all 
    </Proxy> 

    ProxyPass /api http://52.35.118.165/api 
    ProxyPassReverse /api http://52.35.118.165/api 

    ProxyPass/http://localhost:3000/ 
    ProxyPassReverse/http://localhost:3000/ 

    <Location /api> 
       Order allow,deny 
     Allow from all 
    </Location> 

    DirectoryIndex index.html index.php 
</VirtualHost> 
+0

目前還不清楚是什麼你問這個問題。 – VBart

+0

我想設置ServerName/ServerAlias與'sitename',而不是'sitename.com'..所以在瀏覽器中,我可以鍵入sitename,它會去localhost:3000。如果我點擊頁面上的網址將是'sitename/about-us' – draxous

+0

當你輸入「sitename」時,你的瀏覽器需要知道該去哪裏,這在nginx配置中是無法完成的。要在你自己的計算機上完成這項工作,你可以添加一個條目到你的主機文件(linux/OSX上的/ etc/hosts,可能是C:\ Windows \ system32 \ drivers \ etc \ hosts)服務器。您無法爲每個人都這樣做,因爲您無法定義自己的域。 – lucash

回答

0

可能,這將有助於(它可能需要一些小的調整):

server { 
    listen 80; 
    server_name .neptix; 
    index index.php index.html index.htm; 

    location /api { 
     proxy_pass http://52.35.118.165/api; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 

    location/{ 
     proxy_pass http://localhost:3000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 
}