折腾一晚vps,给nginx做域名反向代理失败,请教如何正确设置?

2012-03-20 14:08:11 +08:00
 paloalto
想把jiyin.it这个域名跟放在GAE上的网站绑定,在vps上用LNMP装了nginx,在nginx.conf中添加了

server
{
listen 80;
server_name jiyin.it;

location / {
proxy_pass http://geekiwi.appspot.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

jiyin.it的A记录也已经指向了vps的IP地址199.15.116.122。

但是访问jiyin.it却还是一个PHP探针页面,原先以为是hosts的问题,所以在vps的hosts中加入了:

203.208.45.206 geekiwi.appspot.com

但是还是不行,删掉这段之后访问,却显示502 Bad Gateway。

请教如何设置才能生效?
7787 次点击
所在节点    NGINX
30 条回复
momou
2012-03-20 14:09:50 +08:00
502 Bad Gateway

nginx/0.7.61
paloalto
2012-03-20 14:12:32 +08:00
@momou 因为我刚删掉了vps的hosts中这段:

203.208.45.206 geekiwi.appspot.com

然后就502了。。
momou
2012-03-20 14:26:45 +08:00
自检没有报错?
paloalto
2012-03-20 14:39:19 +08:00
@momou 刚才代码里没有}闭合,但是加上}闭合之后,还是不行

[root@vps www]# /usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

依然跳转到探针页面。

贴出我的nginx.conf文件:

user www www;

worker_processes 1;

error_log /home/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 51200;
}

http
{
include mime.types;
default_type application/octet-stream;

#charse gb2312;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;

server
{
listen 80;
server_name bod.fm;
index index.html index.htm index.php;
root /home/www;

#limit_conn crawler 20;

#location /status {
#stub_status on;
#access_log off;
#}

location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /home/logs/access.log access;
}

server
{
listen 80;
server_name jiyin.it;

location / {
proxy_pass http://geekiwi.appspot.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

server
{
listen 80;
server_name yagbodu.com;

location / {
proxy_pass http://erwenit.appspot.com/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

}
lowstz
2012-03-20 14:49:54 +08:00
server {
listen 81;
server_name jiyin.it;
location / {
proxy_redirect off;
proxy_pass http://geekiwi.appspot.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
paloalto
2012-03-20 14:53:07 +08:00
@lowstz 端口设置为每个server_name都不同?
lowstz
2012-03-20 14:53:56 +08:00
不是,我只是测试,80也可以


自己vps上测试了可以
aggron
2012-03-20 14:58:26 +08:00
jiyin.it 现在代理设置是OK的~~,不过点用户链接是404,还未完成的站点么?
先许个愿:妹子~~~~~
lemonda
2012-03-20 14:59:01 +08:00
本地测试,jiyin.it指向127.0.0.1,反代成功:

vps上jiyin.it应指向vps的IP
只是在http {} 两括号之间加上了:
http://gist.github.com/2132139.js
paloalto
2012-03-20 14:59:18 +08:00
@lowstz 我改动了一下conf文件,然后新加上了你的。结果访问jiyin.it变成一个nginx的欢迎页面了。。。悲催。。。

——————————nginx.conf文件:——————————

user www www;

worker_processes 2;

error_log /home/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 51200;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

server {
listen 81;
server_name jiyin.it;
location / {
proxy_redirect off;
proxy_pass http://geekiwi.appspot.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

}
aggron
2012-03-20 15:00:00 +08:00
现在变成 Welcome to nginx!了
paloalto
2012-03-20 15:02:46 +08:00
@lemonda “vps上jiyin.it应指向vps的IP ”
——
请问你是说的hosts?还是nginx.conf里的proxy_pass项?
lowstz
2012-03-20 15:03:08 +08:00
@paloalto listen 81; 换成 80,我刚才想改81,但是不小心就提交了,
修改之前你现在访问 jiyin.it:81是没有问题的
aggron
2012-03-20 15:05:13 +08:00
server {
listen 80;
server_name jiyin.it;
location / {
proxy_redirect off;
proxy_pass http://geekiwi.appspot.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这样就OK了,
如果listen 81就得用 http://jiyin.it:81/ 来访问了
lemonda
2012-03-20 15:06:27 +08:00
@paloalto nginx.conf里就是gist的代码那样了,我是本地测试才把127.0.0.1 jiyin.it写到hosts里的,你把jiyin.it指向199.15.116.122已经可以了。
ccdjh
2012-03-20 15:11:28 +08:00
server {
listen 80;
server_name www.jiyin.it;

access_log /var/log/nginx/localhost.access.log;

location / {
proxy_pass http://ghs.google.com;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
# root /var/www/nginx-default;
# index index.html index.htm;
}
}
paloalto
2012-03-20 15:14:23 +08:00
把listen 81改成了listen 80后还是欢迎页面,会不会是nginx.conf里第一个server对第二个server有干扰?

重新帖一遍现在的nginx.conf的内容:

——————————nginx.conf文件:——————————

user www www;

worker_processes 2;

error_log /home/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 51200;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

server {
listen 80;
server_name jiyin.it;
location / {
proxy_redirect off;
proxy_pass http://geekiwi.appspot.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

}
aggron
2012-03-20 15:18:52 +08:00
现在OK的,CTRL+F5看看?
lowstz
2012-03-20 15:19:07 +08:00
@paloalto 可以看到基因了,你浏览器多刷新几次,或者关掉重开,或者换一个
paloalto
2012-03-20 15:19:41 +08:00
@ccdjh 新加的access_log是干嘛的?

[emerg]: open() "/var/log/nginx/localhost.access.log" failed (2: No such file or directory)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/30116

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX