Skip to content

Instantly share code, notes, and snippets.

@hiroykam
Last active August 2, 2018 12:39
Show Gist options
  • Select an option

  • Save hiroykam/b11b4f545b011f879b9d22e5d7a94a42 to your computer and use it in GitHub Desktop.

Select an option

Save hiroykam/b11b4f545b011f879b9d22e5d7a94a42 to your computer and use it in GitHub Desktop.
DockerでPython+uWSGI+Nginxの環境を作成 ref: https://qiita.com/hiroykam/items/748c3fab31c616994db9
server {
listen 80 default;
server_name _;
location / {
include uwsgi_params;
uwsgi_pass localhost:8080;
}
location = /favicon.ico {
empty_gif;
}
}
version: "2"
services:
# nginx
nginx-python:
build: ./nginx-python
ports:
- "8080:80"
volumes:
- ./app/:/var/www/html/app/
environment:
TZ: "Asia/Tokyo"
FROM centos:6.8
ADD ./conf/nginx.repo /etc/yum.repos.d/
# nginx & python
RUN yum localinstall -y http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
RUN yum install -y https://centos6.iuscommunity.org/ius-release.rpm
RUN yum install -y nginx-1.10.1
RUN yum install -y make gcc
RUN yum install -y libxml2-devel
RUN yum install -y python35u python35u-libs python35u-devel python35u-pip
RUN yum clean all
RUN ln -s /usr/bin/python3.5 /usr/bin/python3
RUN unlink /usr/bin/python
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -s /usr/bin/pip3.5 /usr/bin/pip
RUN pip install uwsgi
# setting nginx
COPY conf/nginx.conf /etc/nginx/nginx.conf
ADD conf/default.conf /etc/nginx/conf.d/default.conf
RUN usermod -u 1000 nginx
EXPOSE 80
ADD ./conf/start.sh /tmp/start.sh
CMD /bin/sh /tmp/start.sh
$ docker-compose build
$ docker-compose up
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0be4855e99df dockerpython_nginx-python "/bin/sh -c '/bin/..." 2 hours ago Up 2 hours 0.0.0.0:8088->80/tcp dockerpython_nginx-python_1
$ docker stop 0be4855e99df
$ docker start 0be4855e99df
$ docker restart 0be4855e99df
$ docker exec -it 0be4855e99df bash
$docker rm 0be4855e99df
$ touch docker_python/app/uwsgi.log
$ touch docker_python/app/uwsgi.pid
$ docker-compose up --build
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 off;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
#!/bin/sh
/etc/init.d/nginx start
cd /var/www/html/app
chmod -R 777 .
uwsgi --ini uwsgi.ini
[uwsgi]
master = True
socket = localhost:8080
wsgi-file = webapp.py
stats = localhost:8181
logto = uwsgi.log
pidfile = uwsgi.pid
def application(environ, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment