Reputation: 5974
I have configured uwsgi
and nginx
separately for a python production server following this link. I have configured them separately with working configuration. My uwsgi
alone works fine, and nginx
alone works fine. My problem is I am planning to use docker for this setup and am not able to run both uwsgi
and nginx
simultaneously, even though I am using a bash file. Below are the relevant parts in my configuration.
Dockerfile :
#python setup
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN rm /etc/nginx/sites-enabled/default
RUN ln -s mysite.conf /etc/nginx/sites-enabled/
EXPOSE 80
CMD ["/bin/bash", "start.sh"]
mysite.conf
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket
}
server {
listen 80;
server_name aa.bb.cc.dd; # ip address of the server
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # the uwsgi_params file
}
}
start.sh :
service nginx status
uwsgi --socket :8001 --module server.wsgi
service nginx restart
service nginx status # ------- > doesn't get executed :(
out put of the shell file
Can someone help me how to set this up using a bash script ?
Upvotes: 2
Views: 1814
Reputation: 2339
I think there is a very basic but important alternative worth pointing out.
Your initial scenario was:
I don't think you should go with some complicated trick to run both processes in the same container.
You should simply run uwsgi and nginx in separate containers.
That way you achieve:
Upvotes: 1
Reputation: 1324937
Your start.sh
script has the risk to end immediately after executing those two commands.
That would terminate the container right after starting it.
You would need at least to make sure nginx start command does not exit right away.
The official nginx image uses:
nginx -g daemon off;
Another approach would be to keep your script as is, but use for CMD a supervisor, declaring your script in /etc/supervisor/conf.d/supervisord.conf
.
That way, you don't expose yourself to the "PID 1 zombie reaping issue": stopping your container will wait for both processes to terminate, before exiting.
Upvotes: 2