从本地主机访问时出现 404 错误:NGINX uWSGI
404 error when Accessing from local host : NGINX uWSGI
我正在尝试使用 nginx(运行 在一个容器中)配置一个 docker 组合示例,面向 3 个容器 运行 uwsgi 中的一个 python 应用程序。
通过容器的 docker ip 尝试 nginx 时,可以毫无问题地访问该应用程序;但是,当尝试使用 localhost:9999 从主机 url(nginx 绑定到使用端口 9999 的主机)访问它时,我可以访问 nginx 页面,但是任何应用程序 urls 或 /admin / uri 出现 404 错误。
我已经浏览了大量的论坛和 Whosebug 答案,但没有任何运气,有人可以帮我解决这个问题吗?
下面附有更多信息:
我的 docker 撰写文件如下所示:
version: '2'
services:
nginxlb:
build: ./nginx
ports:
- "9999:80"
links:
- my-app1:my-app1
- my-app2:my-app2
- my-app3:my-app3
volumes:
- ./logs/nginx/:/opt/my-logs/nginx/
my-app1:
build: ./my
expose:
- 8080
- 8081
volumes:
- ./logs/node1:/opt/my-logs/node1/
my-app2:
build: ./my
volumes:
- ./logs/node2/:/opt/my-logs/node2/
expose:
- 8080
- 8081
my-app3:
build: ./my
volumes:
- ./logs/node3:/opt/my-logs/node3
expose:
- 8080
- 8081
nginx 的站点启用 conf 如下所示:
upstream node-app {
least_conn;
server my-app1:8080;
server my-app2:8080;
server my-app3:8080;
}
server {
listen 80 default;
server_name _;
location / {
proxy_pass http://node-app;
include /etc/nginx/uwsgi_params;
}
}
编辑 这是我的 Docker NGINX 文件 我没有对默认的 nginx.conf 文件进行任何更改
From nginx
MAINTAINER DevOps
# Update the container
RUN apt-get update
# Create directories and set working directory
RUN mkdir /opt/myapp/
RUN mkdir /opt/myapp/django-static/
RUN mkdir /opt/myapp/django-media/
RUN mkdir /opt/myapp/webroot/
run mkdir -p /opt/myapp-logs/nginx/
WORKDIR /opt/myapp/
# Copy configs and code to Container
ADD config/nginx.conf /etc/nginx/nginx.conf
ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf
ADD config/uwsgi_params /etc/nginx/uwsgi_params
EXPOSE 80
默认站点的 Nginx 配置文件包括行:
server_name localhost;
所以当你去http://localhost:9999
时使用这个配置;另外 - nginx 不处理 /etc/nginx/sites-enabled
目录及其内容;从默认 nginx.conf
:
include /etc/nginx/conf.d/*.conf;
修改您的 Dockerfile - 而不是:
ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf
使用:
RUN rm /etc/nginx/conf.d/default.conf
ADD config/nginx-site.conf /etc/nginx/conf.d/nginx.conf
我正在尝试使用 nginx(运行 在一个容器中)配置一个 docker 组合示例,面向 3 个容器 运行 uwsgi 中的一个 python 应用程序。
通过容器的 docker ip 尝试 nginx 时,可以毫无问题地访问该应用程序;但是,当尝试使用 localhost:9999 从主机 url(nginx 绑定到使用端口 9999 的主机)访问它时,我可以访问 nginx 页面,但是任何应用程序 urls 或 /admin / uri 出现 404 错误。
我已经浏览了大量的论坛和 Whosebug 答案,但没有任何运气,有人可以帮我解决这个问题吗?
下面附有更多信息:
我的 docker 撰写文件如下所示:
version: '2'
services:
nginxlb:
build: ./nginx
ports:
- "9999:80"
links:
- my-app1:my-app1
- my-app2:my-app2
- my-app3:my-app3
volumes:
- ./logs/nginx/:/opt/my-logs/nginx/
my-app1:
build: ./my
expose:
- 8080
- 8081
volumes:
- ./logs/node1:/opt/my-logs/node1/
my-app2:
build: ./my
volumes:
- ./logs/node2/:/opt/my-logs/node2/
expose:
- 8080
- 8081
my-app3:
build: ./my
volumes:
- ./logs/node3:/opt/my-logs/node3
expose:
- 8080
- 8081
nginx 的站点启用 conf 如下所示:
upstream node-app {
least_conn;
server my-app1:8080;
server my-app2:8080;
server my-app3:8080;
}
server {
listen 80 default;
server_name _;
location / {
proxy_pass http://node-app;
include /etc/nginx/uwsgi_params;
}
}
编辑 这是我的 Docker NGINX 文件 我没有对默认的 nginx.conf 文件进行任何更改
From nginx
MAINTAINER DevOps
# Update the container
RUN apt-get update
# Create directories and set working directory
RUN mkdir /opt/myapp/
RUN mkdir /opt/myapp/django-static/
RUN mkdir /opt/myapp/django-media/
RUN mkdir /opt/myapp/webroot/
run mkdir -p /opt/myapp-logs/nginx/
WORKDIR /opt/myapp/
# Copy configs and code to Container
ADD config/nginx.conf /etc/nginx/nginx.conf
ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf
ADD config/uwsgi_params /etc/nginx/uwsgi_params
EXPOSE 80
默认站点的 Nginx 配置文件包括行:
server_name localhost;
所以当你去http://localhost:9999
时使用这个配置;另外 - nginx 不处理 /etc/nginx/sites-enabled
目录及其内容;从默认 nginx.conf
:
include /etc/nginx/conf.d/*.conf;
修改您的 Dockerfile - 而不是:
ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf
使用:
RUN rm /etc/nginx/conf.d/default.conf
ADD config/nginx-site.conf /etc/nginx/conf.d/nginx.conf