如何为反向代理配置nginx

时间:2017-06-14 09:15:48

标签: nginx proxy

我想通过172.17.0.4:8080/swagger-u.html反向代理172.17.0.6:8080/swagger-u.html或172.17.0.8:8080/swagger-u.html,我需要配置Nginx,请帮忙! 这是我的nginx.conf:

[root@5e1ae14b79e8 /]# vi /etc/nginx/nginx.conf 
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
     events {
    worker_connections 1024;
}

http {
   upstream backends {
        server 172.17.0.7:8012 weight=3;
        server 172.17.0.6:8012;
    }
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  172.17.0.4;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /wagger-u.html/ {
                  proxy_pass http://backends;
                  proxy_redirect  off;
                  proxy_set_header Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
        }

        error_page 404 /404.html;
            location = /40x.html {

但是,我访问172.17.0.4:8080/swagger-u.html,it是404!

0 个答案:

没有答案