我有2个django项目,这些项目配置为在套接字上提供服务。
它们在同一台服务器上。 Django项目名称为 proj1 和 proj2 。所以我在 / etc / hosts 文件上给了他们两个不同的名称 proj1.cr.tm 和 proj2.cr.tm 指向相同的本地 127.0.0.1 地址。因此,当我ping proj1.cr.tm 时,它会ping 127.0.0.1;当我ping proj2.cr.tm 时,它也会ping 127.0.0.1。因此,我要在端口80上同一服务器ip上的这两个不同域名上为2个项目提供服务。名称和项目的区分将由nginx进行。
我还在 /etc/nginx/conf.d 目录下准备了2个nginx配置 proj1.conf 和 proj2.conf 并添加了< b> proj1.cr.tm 和 proj2.cr.tm 作为这些配置中的服务器。我还将它们包含在 /etc/nginx/nginx.conf 文件下的主要 nginx.conf 文件中。
我还为uwsgi准备了2个ini文件,并与皇帝一起运行uwsgi。当我运行uwsgi和nginx时,我可以看到已创建套接字文件。 而且我还可以看到nginx正在使用默认的nginx页面在http:/127.0.0.1上工作。我还看到带有项目模块的uwsgi进程正在后面的linux进程中工作。但是当我尝试使用http://proj1.cr.tm和http://proj2.cr.tm地址时,我仍然看不到我的django网站。我仍然看到nginx默认页面。
我检查了目录和套接字以及conf文件和ini文件的权限。他们看起来还不错。当我使用runserver运行django站点或使用“ uwsgi --http:8081 --module proj1.wsgi” 运行它们时,它们正在工作。但是我不能用nginx服务它们。
更新:
项目1的nginx配置:
server {
listen 80;
server_name proj1.cr.tm;
access_log /var/log/nginx/proj1_access.log;
error_log /var/log/nginx/proj1_errors.log;
sendfile on;
client_max_body_size 20M;
keepalive_timeout 0;
location = favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/proj1/work/proj1;
}
location /media/ {
root /home/proj1/work/proj1;
}
location / {
include uwsgi_params;
uwsgi_read_timeout 9000;
uwsgi_send_timeout 9000;
uwsgi_connect_timeout 9000;
uwsgi_pass unix:/run/uwsgi/proj1.sock;
}
}
项目2的nginx配置:
server {
listen 80;
server_name proj2.cr.tm;
access_log /var/log/nginx/proj2-nec_access.log;
error_log /var/log/nginx/proj2-nec_errors.log;
location = favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/proj2/work/proj2;
}
location /user/ {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/proj2.sock;
uwsgi_read_timeout 900;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/proj2.sock;
}
}
proj1的uwsgi ini conf:
[uwsgi]
py-autoreload = 2
project = proj1
username = proj1
base = /home/%(username)
chdir = %(base)/work/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = %k
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 666
vacuum = true
#logto = /var/log/uwsgi/%(project).log
proj2的uwsgi ini conf:
[uwsgi]
py-autoreload = 2
project = proj2
username = proj2
base = /home/%(username)
chdir = %(base)/work/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = %k
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 666
vacuum = true
#logto = /var/log/uwsgi/%(project).log
nginx conf:
# * For information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}