系统:centos
进程1:nginx (docker容器)
进程2:uwsgi(宿主机)
# mysite_nginx.conf
# the upstream component nginx needs to connect to
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 (we'll use this first)
server 10.2.20.5:8001;
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 127.0.0.1; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /static {
alias /usr/share/nginx/html/static; # your Django project's static files - amend as required
index index.html index.htm;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/photo
# Django's wsgi file
module = photo.wsgi
# the virtualenv (full path)
home = /home/env/djobjenv
# virtualenv= /home/dj/.virtualenvs/dj
env =DJANGO_SETTINGS_MODULE=photo.settings_deploy
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 3
# the socket (use the full path to be safe
socket = 0.0.0.0:8001
# http = :8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
问题 一:两者无法通讯
docker 宿主机属于两台不同的电脑,需要使用内网IP
问题二:文件映射
docker run
--rm
-it
-d
-v /home/photo/django.conf:/etc/nginx/conf.d/django.conf
-v /home/docker_static:/usr/share/nginx/html
-p 8000:8000
nginx:1.20.1-alpine