我看着周圍的答案,我相信答案是很簡單,但我沒能找到它。我覺得我缺乏nginx的知識......的nginx /瓶蟒蛇 - 路由請求到另一個端口
我有我的nginx的實例運行在localhost:8080,我的瓶服務器偵聽在localhost:8081。如果我從瀏覽器打開地址,它們工作正常,但是當我嘗試從localhost:8080上運行的應用程序訪問時,我無法檢索Bottle服務器生成的資源。
我需要做的就是重定向,一個在我的瓶子服務器監聽到/數據/路徑相同的域(本地主機),但其他端口(8081)提出的所有電話。
下面是代碼: Nginx的:
server {
listen 8080;
server_name localhost;
root /Users/Diego/Desktop;
location/{
index index.html index.htm;
}
location /data/ {
proxy_pass http://127.0.0.1:8081;
}
}
瓶服務器:
@route('/')
def printtest():
print 'success'
return 'loaded page'
@route('/<scenename>/data/<filename:path>')
def testMethod(scenename,filename):
print scenename, filename
run(host='localhost', port=8081, debug=True)
調用瀏覽器爲localhost:8080,顯示我通過nginx的服務頁面,但是呢,如果我調用一個鏈接來檢索存儲在/data/directory/filename.json中的東西,Bottle看起來並沒有收到請求。錯誤日誌中指出:
2013/04/16 18:50:52 [error] 3544#10612: *69 CreateFile() "C:/Users/Diego/Desktop/project1/data/directory/directory-varietal.json" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /project1/data/directory/directory-varietal.json HTTP/1.1", host: "localhost:8081", referrer: "http://localhost:8080/project1/"
有誰能夠告訴我該如何處理這種重定向/路由?
另外,有沒有辦法打印從nginx的日誌源?像命令print_entry或類似?
謝謝!
編輯:我試過,但沒有結果... https://serverfault.com/questions/208656/routing-to-various-node-js-servers-on-same-machine
編輯:好吧一些改進,我發現可能是查詢地點的問題。使用此塊並請求.json文件時,它實際上會查詢Bottle服務器。
location ~* \.(json)$ {
proxy_pass http://localhost:8081;
}
編輯:呀!我找到了一個解決方案......原來這是在該位置定義的路徑問題。注意自我:仔細閱讀說明書:http://wiki.nginx.org/HttpCoreModule#location
新代碼服務器:
server {
listen 8080;
server_name localhost;
root /Users/Diego/Desktop;
location/{
index index.html index.htm;
}
location ~* /data/ {
proxy_pass http://localhost:8081;
}
}
無論如何,如果任何人有一個更好的解決方案或任何建議更多的則是歡迎作出貢獻。
很高興聽到你解決它 - 感謝回來後的解決方案! –
@Dieghito,請將您的更新發布爲正確答案。回答你自己的問題是可以接受的。 – Rod
謝謝@Rod,完成。 – Dieghito