V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
paloalto
V2EX  ›  NGINX

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

  •  
  •   paloalto · 2012-03-20 14:08:11 +08:00 · 7792 次点击
    这是一个创建于 4632 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想把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。

    请教如何设置才能生效?
    30 条回复    1970-01-01 08:00:00 +08:00
    momou
        1
    momou  
       2012-03-20 14:09:50 +08:00
    502 Bad Gateway

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

    203.208.45.206 geekiwi.appspot.com

    然后就502了。。
    momou
        3
    momou  
       2012-03-20 14:26:45 +08:00
    自检没有报错?
    paloalto
        4
    paloalto  
    OP
       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
        5
    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
        6
    paloalto  
    OP
       2012-03-20 14:53:07 +08:00
    @lowstz 端口设置为每个server_name都不同?
    lowstz
        7
    lowstz  
       2012-03-20 14:53:56 +08:00
    不是,我只是测试,80也可以


    自己vps上测试了可以
    aggron
        8
    aggron  
       2012-03-20 14:58:26 +08:00
    jiyin.it 现在代理设置是OK的~~,不过点用户链接是404,还未完成的站点么?
    先许个愿:妹子~~~~~
    lemonda
        9
    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
        10
    paloalto  
    OP
       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
        11
    aggron  
       2012-03-20 15:00:00 +08:00
    现在变成 Welcome to nginx!了
    paloalto
        12
    paloalto  
    OP
       2012-03-20 15:02:46 +08:00
    @lemonda “vps上jiyin.it应指向vps的IP ”
    ——
    请问你是说的hosts?还是nginx.conf里的proxy_pass项?
    lowstz
        13
    lowstz  
       2012-03-20 15:03:08 +08:00
    @paloalto listen 81; 换成 80,我刚才想改81,但是不小心就提交了,
    修改之前你现在访问 jiyin.it:81是没有问题的
    aggron
        14
    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
        15
    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
        16
    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
        17
    paloalto  
    OP
       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
        18
    aggron  
       2012-03-20 15:18:52 +08:00
    现在OK的,CTRL+F5看看?
    lowstz
        19
    lowstz  
       2012-03-20 15:19:07 +08:00
    @paloalto 可以看到基因了,你浏览器多刷新几次,或者关掉重开,或者换一个
    paloalto
        20
    paloalto  
    OP
       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)
    paloalto
        21
    paloalto  
    OP
       2012-03-20 15:20:39 +08:00
    @lowstz @aggron 你们那边都可以直接用jiyin.it访问吗?我这边怎么还不行。。。。纠结。。
    aggron
        22
    aggron  
       2012-03-20 15:22:57 +08:00
    是的,能直接访问
    CTRL+F5,
    或者清空你本地的DNS缓存看看
    paloalto
        23
    paloalto  
    OP
       2012-03-20 15:25:39 +08:00
    @lemonda @ccdjh @aggron @lowstz 多谢大家的帮忙,我刚换了台电脑能访问了。

    应该是我自己那台电脑的hosts文件有问题,以前加过google的hosts。

    再次感谢!
    aggron
        24
    aggron  
       2012-03-20 15:36:06 +08:00
    提交表单后的跳转貌似有点问题:
    点“说出来”后,chrome左下角显示”正在向geekiwi.appspot.com提交数据“,然后chrome地址栏就变成了geekiwi.appspot.com,于是显示被墙。再进入jiyin.it可以看到刚发布的内容
    guoquan
        25
    guoquan  
       2012-03-20 15:44:30 +08:00
    ^_^ 要不要上个LUManager试试呀 http://www.v2ex.com/t/29571
    paloalto
        26
    paloalto  
    OP
       2012-03-20 15:56:06 +08:00
    @aggron 我也遇到这问题,但是不知道什么原因。。。

    @guoquan 我用的是Cyberduck,还挺好用的。
    guoquan
        27
    guoquan  
       2012-03-20 16:37:05 +08:00
    @paloalto LUManager在vps管理上很全面,web服务器就是apache+nginx+tengine,1.1.9免费版就已经很强悍了,设置个反向代理什么的不在话下。
    最近开始走商业化的2.0.x版更加面面俱到,都可以拿出来直接做idc了,个人使用更加游刃有余,欢迎了解哦。
    liuhang0077
        28
    liuhang0077  
       2012-03-20 17:06:10 +08:00
    不用那么多吧~~~
    server
    {
    listen 80;
    server_name www.aaa.com;

    location / {
    proxy_pass http://www.bbbb.com/;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    }
    CoX
        29
    CoX  
       2012-03-20 17:42:11 +08:00
    访问了一下,可以正常访问啊
    blacktulip
        30
    blacktulip  
       2012-03-20 17:44:39 +08:00
    @guoquan 麻烦您不要在技术讨论帖里面发这种广告了,好好的讨论串里面突然给你插一个这样的帖子
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   919 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 19:52 · PVG 03:52 · LAX 11:52 · JFK 14:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.