nodejs express的nginx反向代理,使用ip地址而不是域名

时间:2016-12-09 21:00:58

标签: node.js express nginx reverse-proxy

我有nginx作为node.js表达应用程序的反向代理。  我可以访问

http://ip:8081/data/emoji.json 

但它不适用于域名

 http://domain_name/data/emoji.json

不起作用。 这是nginx的配置:

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

    index index.html index.htm index.nginx-debian.html;
    server_name domain_name;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            proxy_pass http://127.0.0.1:8081;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }

        location /mongo {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header Host $http_host;
            proxy_redirect off;

            if (!-f $request_filename) {
                rewrite /mongo/(.+) /$1 break;
                proxy_pass http://127.0.0.1:28017;
                break;
            }
        }
}

0 个答案:

没有答案