› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
evenno
V2EX  ›  NGINX

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

  •  
  •   evenno · Oct 15, 2015 · 5357 views
    This topic created in 4050 days ago, the information mentioned may be changed or developed.

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

    9 replies  •  2015-10-16 09:25:59 +08:00
    evenno
    evenno
    OP
    Oct 15, 2015
    1
    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
    fising
    Oct 15, 2015
    2
    location /test {
    proxy_pass http://ip:80;
    }
    evenno
    evenno
    OP
    Oct 15, 2015
    3
    @fising 不行哦, service nginx reload fail
    ryd994
    ryd994
    Oct 15, 2015
    4
    @evenno 贴 errorlog
    evenno
    evenno
    OP
    Oct 15, 2015
    5
    2015/10/15 14:10:49 [emerg] 789#0: directive "proxy_pass" is not terminated by ";" in /etc/nginx/sites-enabled/api:24
    lution
    lution
    Oct 15, 2015
    6
    @evenno 少了分号。。
    evenno
    evenno
    OP
    Oct 15, 2015
    7
    @lution ok,感谢
    3pointer
    3pointer
    Oct 15, 2015
    8
    写完配置,查一下语法
    FingerLiu
    FingerLiu
    Oct 16, 2015❤️1
    9
    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.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2536 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 00:34 · PVG 08:34 · LAX 16:34 · JFK 19:34
    ♥ Do have faith in what you're doing.