使用docker的Nginx:反向代理不起作用

问题描述 投票:0回答:1

我最近想设置一个反向代理服务器。我拉了一个nginx码头工人图像,并使用以下命令运行了Docker容器:

docker run -d --name ngtest -p 4080:80 nginx

然后我像下面这样更新了/etc/nginx/nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    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;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    server{
        listen 80;
        location /nexus/ {
            proxy_pass    http://192.168.0.30:8081/;
        }
    }
}

当我尝试打开页面时,容器在重新启动后可以工作http://192.168.0.30:4080,我得到了默认的Nginx页面。

但是,当我尝试使用此URL:http://192.168.0.30:4080/nexus时,我得到了一个404页,且有错误。

从日志中看,nginx似乎没有将URL转发到我在nginx.conf中设置的页面,而是尝试在本地目录中查找页面:

2020/03/11 16:10:34 [error] 6#6: *251 open() "/usr/share/nginx/html/nexus" failed (2: No such file or directory), client: 192.168.0.153, server: localhost, request: "GET /nexus HTTP/1.1", host: "192.168.0.30:4080"
192.168.0.153 - - [11/Mar/2020:16:10:34 +0000] "GET /nexus HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" "-"

我的步骤有什么问题吗?

谢谢,

Alex

我最近想设置一个反向代理服务器。我拉了一个nginx docker映像,并使用以下命令运行了docker容器:docker run -d --name ngtest -p 4080:80 nginx然后我更新了/ etc / ...

docker nginx reverse-proxy
1个回答
0
投票

问题是,即使使用更新的配置,您仍在做:

© www.soinside.com 2019 - 2024. All rights reserved.