我在让Nginx服务于静态index.html页面时遇到了一些麻烦,同时也为Django网站提供服务。 有人能指出我做错了吗?
80
和8000
。我将uwsgi_params放在/etc/nginx/uwsgi_params
的/ etc / nginx的/启用的站点 -
以下是我对实际配置文件的符号链接
site1.conf -> /home/jesse/projects/site1/conf/site1.conf
site2.conf -> /home/jesse/projects/site2/conf/site2.conf
/home/jesse/projects/site1/conf/site1.conf
这只是一个基本的静态网站,但不会加载:(
server {
listen 80;
server_name www.site1.com;
rewrite ^(.*) http://site1.com$1 permanent;
location / {
root /home/jesse/projects/site1/;
}
}
/home/jesse/projects/site2/conf/site2.conf
= manage.py/wsgy.py
位于/home/jesse/projects/site2/site2/
=这是一个使用 uWSGI 的Django网站,我用$ pip install uwsgi
安装了它。
server {
listen 80;
server_name www.site2.com;
rewrite ^(.*) http://site2com$1 permanent;
root /home/site2/projects/site2/site2;
location /static/ {
alias /home/jesse/site2/projects/site2/site2/static/;
#expires 30d;
}
location /media/ {
alias /home/jesse/site2/projects/site2/site2/media/;
#expires 30d;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
/家庭/站点2 /项目/站点2 / CONF
[uwsgi]
projectname = site2
projectdomain = site2.com
base = /home/jesse/site2/projects/site2/site2
# Config
plugins = python
master = true
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
pythonpath = %(base)/src/%(projectname)
module = %(projectname).wsgi
socket = 127.0.0.1:8000
logto = %(base)/logs/uwsgi.log
# Runs daemon in background
daemonize = /home/jesse/log/$(projectname).log
Nginx重启
$ sudo service nginx restart
* Restarting nginx nginx [ OK ]
= site1产生Not Found(不是404)
= site2生成
我将不胜感激任何帮助:)
答案 0 :(得分:0)
rewrite ^(.*) http://site1.com$1 permanent;
这在site1中,不由任何服务器管理,因为没有server_name处理site.com(没有www)。
然后再次使用site2
rewrite ^(.*) http://site2com$1 permanent;
首先修复这些行。
我认为正确的方法是编写一个捕获www的服务器规则。命名并将它们重写为非www,并将site1.com或site2.com作为server_name放在您现在的规则中,作为重新布线的示例
server {
listen 80;
server_name www.site1.com
return 301 http://site1.com$request_uri?;
}