我正在使用 nginx 和 uwsgi 在 elastic beanstalk 和 docker 中部署 django 应用程序。
以下是 Dockerfile:
FROM ubuntu:14.04
MAINTAINER Nijo James
# Update packages
RUN apt-get update -y
#Install python Setuptools
RUN apt-get install -y python python-dev python-setuptools python-software-properties
RUN apt-get install -y libpq-dev
RUN apt-get install -y supervisor
RUN apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev
RUN apt-get install -y build-essential libssl-dev libffi-dev
#TO install pillow
RUN apt-get install -y libjpeg-dev
# update packages after adding nginx repository
RUN apt-get update
# install latest stable nginx
RUN apt-get install -y nginx
#setup redis-server
RUN apt-get install -y redis-server
#Install pip
RUN easy_install pip
# Install uwsgi
RUN pip install uwsgi
# copy the contents of this directory over to the container at location /src
ADD . /home/docker/src/
# run pip install
RUN pip install -r /home/docker/src/server/requirements.txt
# Customize configurations
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN rm /etc/nginx/sites-enabled/default
RUN rm /etc/nginx/sites-available/default
RUN ln -s /home/docker/src/server/nginx-app.conf /etc/nginx/sites-enabled/
RUN ln -s /home/docker/src/server/supervisor-app.conf /etc/supervisor/conf.d/
RUN mkdir -p /home/docker/src/server/logs/
EXPOSE 80
#Run command
cmd ["/home/docker/src/server/start.sh"]
但是当我尝试通过网络访问它时,我得到了502 Bad Gateway
。
当我尝试 cURL Docker IP 时,出现了同样的错误。
Elastic Beanstalk 错误日志有以下错误:
[error] 29386#0: *1986 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.43.60, server: , request: "GET / HTTP/1.1", upstream: "http://[dockerip]:80/", host: "xxxxxxxxxxxxx.elasticbeanstalk.com"
这是我的 nginx 配置:
upstream django
{
server unix:/tmp/api.sock; # for a file socket
}
server
{
listen 80 default_server;
charset utf-8;
# max upload size
client_max_body_size 4G; # adjust to taste
location / {
uwsgi_pass django;
include /home/docker/src/server/uwsgi_params; # the uwsgi_params file you installed
}
sendfile off;
access_log /home/docker/src/server/logs/nginx-access.log;
error_log /home/docker/src/server/logs/nginx-error.log;
来自docker内部的uwsgi错误日志:
当前工作目录:/home/docker/src/server
检测到的二进制路径:/usr/local/bin/uwsgi
!!! 没有内部路由支持,使用 pcre 支持重建 !!!
uWSGI 以 root 身份运行,你可以使用 --uid/--gid/--chroot 选项
* 警告:你正在以 root 身份运行 uWSGI !!! (使用 --uid 标志) * chdir() 到 /home/docker/src/server/