我将nginx设置为Thin Rails应用服务器的反向代理。
server {
listen 82;
server_name www.hamburgers.com;
root /var/user_cases/user_00001/user_case_11/public;
location ~\.* {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
}
}
打开一些页面,请参阅/var/log/nginx/access.log
127.0.0.1 - - [28/May/2012:18:33:53 +0400] "GET /assets/e.png HTTP/1.1" 304 0 "http://www.hamburgers.com:82/user_session/new" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0"
127.0.0.1 - - [28/May/2012:18:34:01 +0400] "POST /user_session HTTP/1.1" 302 113 "http://www.hamburgers.com:82/user_session/new" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0"
但有些人在/var/log/nginx/error.log
2012/05/28 18:34:03 [error] 5710#0: *117 open() "/var/www/nginx-default/user_cases" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /user_cases HTTP/1.1", host: "www.hamburgers.com", referrer: "http://www.hamburgers.com:82/user_session/new"
我认为nginx出于某种原因使用/var/www/nginx-default
而不是www.humburgers.com
来表示某些页面。我不知道为什么。
我该如何解决?
答案 0 :(得分:3)
找到解决方案。我应该用
proxy_set_header Host $http_host;
而不是
proxy_set_header Host $host;