11
我在我的服務器ansel.ms上運行nginx,在ansel.ms:46156上運行node.js應用程序。如何使用nginx將address.com/foo/bar重定向到address.com:port/bar?
我想設置Nginx的所以它重定向一切從
ansel.ms/rhythm
到
ansel.ms:46156.
ansel.ms/rhythm/sub/path
應該成爲
ansel.ms:46156/sub/path
這是我在文件地點可用:
upstream rhythm {
server ansel.ms:46156;
}
server {
listen 80;
server_name ansel.ms www.ansel.ms;
access_log /srv/www/ansel.ms/logs/access.log;
error_log /srv/www/ansel.ms/logs/error.log;
location/{
root /srv/www/ansel.ms/public_html;
index index.html index.htm;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/ansel.ms/public_html$fastcgi_script_name;
}
location /rhythm{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://rhythm;
proxy_redirect off;
}
}
我真的不知道這件事(proxy_set_header的東西),我只複製了&從幾個來源粘貼它。
它不起作用。
你能給我一個提示什麼改變,所以它做我上面描述的? 謝謝!
謝謝!你可以用下面的方法修正斜線問題:'server {... server_name_in_redirect off; ...}'你必須像這樣添加一個斜槓到你的位置:'location/rhythm/{...'(但不是在重寫!) – 2011-02-07 17:49:06
這是一種'擱置',但你也使用nginx做POST請求的日誌記錄。我可以很好地記錄我的GET請求,但是我無法記錄POST請求的正文響應。只是想你可能有一些洞察力。我的問題發佈在:http://stackoverflow.com/questions/4939382/logging-post-data-from-request-body – 2011-02-08 22:54:17
我很高興在我需要的時間發現了這個問題。爲Anselm Eickhoff提供額外的青銅色點綴。 – Kawa 2013-04-04 18:37:46