我在我的Production服务器上设置了Django + nginx + uwsgi堆栈,我试图让它在端口80上运行。为了测试我的Django应用程序,我尝试了manage.py runserver 0.0.0.0:80但是它给了我一个权限问题。我试图sudo命令,但django只安装在我的virtualenv上,所以它遇到了问题。我可以通过浏览器在端口80上点击我的服务器,它有默认的nginx启动页面。这是我的配置文件:
nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on and the domain name it will serve for
listen 8000;
server_name ip-address-here; # substitute your machine's IP address or FQD
root /home/user1;
access_log /home/user1/logs/access.log;
error_log /home/user1/logs/error.log;
charset utf-8;
gzip on;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media/ {
alias /home/user1/Project/static/img/; # your Django project's media files - ame$
}
location /static/ {
alias /home/user1/Project/static/; # your Django project's static files - amend a$
}
location /img/ {
autoindex on;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass 127.0.0.1:8889;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi.ini
[uwsgi]
# variables
projectname = Project
projectdomain = project.com
base = /home/user1
# config
master = true
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
pythonpath = %(base)/%(projectname)
module = %(projectname).wsgi:application
socket = 127.0.0.1:8889
logto = %(base)/logs/uwsgi.log
#below line runs it as a daemon in background
daemonize = /home/user1/logs/project_uwsgi.log
另外,在运行这样的堆栈时,我应该设置什么样的用户? IE浏览器。我应该用什么用户运行nginx?我应该在哪个用户下设置项目?目前,我的项目设置在/ home / user1目录下,我正在运行nginx作为user1。我也使用user1来ssh到我的机器。我出于安全目的禁用了root帐户,但user1具有sudo权限。
答案 0 :(得分:1)
你在端口8000上有nginx服务,但它应该是80。
如果您是通过发行版的软件包管理器安装的,它应该为您设置用户。