运行 端口 80 上的 django 应用程序使用 nginx
Running django application on port 80 using nginx
我在我的生产服务器上设置了一个 Django+nginx+uwsgi 堆栈,我正试图将它连接到端口 80 上的 运行。为了测试我的 Django 应用程序,我尝试了 manage.py 运行server 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 目录下,我 运行ning nginx 作为 user1。我还使用 user1 ssh 进入我的机器。为了安全起见,我禁用了 root 帐户,但 user1 具有 sudo 权限。
您的 nginx 在端口 8000 上服务,但它应该是 80。
如果您是通过发行版的包管理器安装的,它应该会为您设置用户。
我在我的生产服务器上设置了一个 Django+nginx+uwsgi 堆栈,我正试图将它连接到端口 80 上的 运行。为了测试我的 Django 应用程序,我尝试了 manage.py 运行server 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 目录下,我 运行ning nginx 作为 user1。我还使用 user1 ssh 进入我的机器。为了安全起见,我禁用了 root 帐户,但 user1 具有 sudo 权限。
您的 nginx 在端口 8000 上服务,但它应该是 80。
如果您是通过发行版的包管理器安装的,它应该会为您设置用户。