求教 关于 nginx 地址转发的问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
evenno
V2EX    NGINX

求教 关于 nginx 地址转发的问题

  •  
  •   evenno 2015-10-15 14:21:32 +08:00 4734 次点击
    这是一个创建于 3726 天前的主题,其中的信息可能已经有所发展或是发生改变。

    当请求访问 /test/下的文件是,转发到 ip : 80 端口上,这个在 nginx 下该如何配置

    9 条回复    2015-10-16 09:25:59 +08:00
    evenno
        1
    evenno  
    OP
       2015-10-15 14:22:44 +08:00
    upstream api_servers {
    server 127.0.0.1:9500;
    #http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
    keepalive 16;
    }
    server {
    listen 80;
    server_name www.yuming.com;
    root /home/yuming/web;

    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    location ~*\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar|txt|amr|js|css|html?)$ {
    root /home/yuming/web;
    }


    location / {
    proxy_pass http://api_servers;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    }

    }
    fising
        2
    fising  
       2015-10-15 14:42:22 +08:00
    location /test {
    proxy_pass http://ip:80;
    }
    evenno
        3
    evenno  
    OP
       2015-10-15 15:00:42 +08:00
    @fising 不行哦, service nginx reload fail
    ryd994
        4
    ryd994  
       2015-10-15 15:01:38 +08:00
    @evenno 贴 errorlog
    evenno
        5
    evenno  
    OP
       2015-10-15 15:04:35 +08:00
    2015/10/15 14:10:49 [emerg] 789#0: directive "proxy_pass" is not terminated by ";" in /etc/nginx/sites-enabled/api:24
    lution
        6
    lution  
       2015-10-15 15:20:35 +08:00
    @evenno 少了分号。。
    evenno
        7
    evenno  
    OP
       2015-10-15 15:22:03 +08:00
    @lution ok,感谢
    3pointer
        8
    3pointer  
       2015-10-15 15:23:36 +08:00
    写完配置,查一下语法
    FingerLiu
        9
    FingerLiu  
       2015-10-16 09:25:59 +08:00   1
    location 好像需要在 server 里面配吧。
    http://nginx.org/en/docs/beginners_guide.html

    Configuration File ’ s Structure

    nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }). If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).

    Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events and http directives reside in the main context, server in http, and location in server.

    The rest of a line after the # sign is considered a comment.
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2598 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 37ms UTC 14:56 PVG 22:56 LAX 06:56 JFK 09:56
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86