CentOS下配置nginx,相同域名映射不同服务地址

    upstream api_server {
        server 127.0.0.1:10010;
    }
    upstream eureka_server {
        server 127.0.0.1:10086;
    }
    server {
        listen 80;
        server_name abc.def.com;
        location / {
            proxy_pass http://127.0.0.1:10010;
            proxy_set_header Host $host:$server_port;
        }
        location /api/ {
            proxy_pass http://api_server/;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /eureka/ {
            proxy_pass http://eureka_server/;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
#        location ~ .* {
#            proxy_pass http://eureka_server;
#            proxy_set_header Host $http_host;
#            proxy_set_header X-Real-IP $remote_addr;
#            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#        }
    }

 

先停nginx,再启动nginx

/www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf

 

你可能感兴趣的:(Linux,linux,centos,nginx)