我正在尝试使用Nginx来服务两个Django网站。
我可以很容易地服务其中一个,但是如果我同时激活两个网站,它会将两个URL发送到一个网站。这是我第一次使用Nginx,我通常使用Apache,请耐心等待。
我在启用的sites中有两个网站,看起来像这样:
site1.com:
这是我的nginx.conf文件的样子:
我本来以为将uwsgi_pass设置为不同的端口会防止它们进入相同的端口,但很明显我错了。我希望能得到任何帮助,谢谢!
我可以很容易地服务其中一个,但是如果我同时激活两个网站,它会将两个URL发送到一个网站。这是我第一次使用Nginx,我通常使用Apache,请耐心等待。
我在启用的sites中有两个网站,看起来像这样:
site1.com:
server{
server_name www.site1.com;
listen 69.164.211.85:80;
access_log /var/www/site1.env/logs/access.log;
error_log /var/www/site1.env/logs/error.log;
location /static/ {
# Point this wherever the static files for your django app are $
autoindex on;
alias /var/www/site1.env/Site1/static/;
}
location / {
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
uwsgi_param UWSGI_APPID site1;
uwsgi_param UWSGI-FILE /var/www/site1.env/Site1/wsgi/site1_wsgi.py;
}
}
site2.net
server{
server_name www.site2.net;
listen 69.164.211.85:80;
access_log /var/www/site2.env/logs/access.log;
error_log /var/www/site2.env/logs/error.log;
location /static/ {
# Point this wherever the static files for your django app are $
autoindex on;
alias /var/www/site2.env/Site2/static/;
}
location / {
uwsgi_pass 127.0.0.1:3032;
include uwsgi_params;
uwsgi_param UWSGI_APPID site2;
uwsgi_param UWSGI-FILE /var/www/site2.env/Site2/wsgi/site2.py;
}
}
我也在运行两个UWSGI实例,这些实例使用以下脚本启动:
网站1:
description "uWSGI server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi \
--home /var/www/site1.env/Site1/ \
--socket 127.0.0.1:3031 \
--chmod-socket \
--module site1_wsgi \
--pythonpath /var/www/site1.env/Site1/wsgi \
-H /var/www/site1.env
网站2:
description "uWSGI server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi \
--home /var/www/site2.env/Site2/ \
--socket 127.0.0.1:3032 \
--chmod-socket \
--module site2 \
--pythonpath /var/www/site2.env/Site2/wsgi \
-H /var/www/sit2.env
这是我的nginx.conf文件的样子:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我本来以为将uwsgi_pass设置为不同的端口会防止它们进入相同的端口,但很明显我错了。我希望能得到任何帮助,谢谢!
www.
前缀进行调用,那么谁来处理这些请求呢?你是否有一个默认的server { server_name _; }
定义? - Tisho