简体   繁体   English

使用Nginx在端口80上运行Django应用程序

[英]Running django application on port 80 using nginx

I have a Django+nginx+uwsgi stack set up on my Production server and I'm trying to get it to run on port 80. To test my Django app, I tried manage.py runserver 0.0.0.0:80 but it gave me a permissions issue. 我在生产服务器上设置了Django + nginx + uwsgi堆栈,试图将其运行在端口80上。为了测试Django应用,我尝试了manage.py runserver 0.0.0.0:80,但它给了我权限问题。 I attempted to sudo the command but django is only installed on my virtualenv so it ran into issues. 我尝试使用sudo命令,但django仅安装在我的virtualenv上,因此遇到了问题。 I can hit my server on port 80 through a browser and it has the default nginx splash page. 我可以通过浏览器在端口80上访问我的服务器,它具有默认的nginx启动页面。 Here are my config files: 这是我的配置文件:

nginx.conf 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.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

Also, when it comes to running a stack like this, what kind of users should I have set up? 另外,在运行这样的堆栈时,应该设置什么样的用户? Ie. IE浏览器。 What user should I run nginx as? 我应该以什么用户身份运行nginx? What user should I set up my project under? 我应该在哪个用户下设置我的项目? Currently, I have my project set up under the /home/user1 directory, and I'm running nginx as user1. 目前,我在/ home / user1目录下设置了项目,并且以user1身份运行nginx。 I also use user1 to ssh into my machine. 我还使用user1 SSH进入我的计算机。 I have disabled the root account for security purposes, but user1 has sudo privileges. 为了安全起见,我已禁用了根帐户,但是user1具有sudo特权。

You have nginx serving on port 8000, but it should be 80. 您的端口8000上有nginx服务,但应该为80。

If you installed it through your distribution's package manager, it should set up the users for you. 如果是通过发行版的程序包管理器安装的,则它应该为您设置用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM