nginx反向代理来表达docker容器内的服务器

时间:2018-06-06 08:47:12

标签: express docker nginx

我遇到了将dock_pass请求发送到docker容器内的Express服务器的麻烦 以下是我的设置:

  1. Docker容器内的Express服务器。我在快递服务器上设置了两条路线,即'/'和'/ accounts'。 docker文件与nodejs官方网站上提供的文件相同 docker使用命令运行:
    docker run -p 7777:8000 -d myImage

  2. Nginx配置到proxy_pass到端口7777.我也安装了让我们加密nginx
    问题是,当我卷曲localhost:7777或卷曲localhost:7777 / accounts时,它将正确响应请求。但是当我试图请求使用我在nginx中设置的域名(example.com)时,它只会响应example.com请求。
    在example.com/accounts中,它将返回'404 not found'。

  3. 编辑: nginx config(来自awnser,删除了注释,重新排序了一下)

    server {
        server_name example.com www.example.com;
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
        location /{
            proxy_redirect off;
            proxy_pass http://127.0.0.1:7777;
            proxy_set_header Host $host;
            try_files $uri $uri/ =404;
        }
    }
    
    server {
        listen 80 default_server;
            listen [::]:80 default_server;
    
            server_name www.example.com example.com;
        return 404; # managed by Certbot
    
        if ($host = example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
        if ($host = example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    }
    

0 个答案:

没有答案