search

Home  >  Q&A  >  body text

ubuntu16.04 - nginx+uwsgi deploys django, port 8000 is normal, port 80 is 404

Use nginx+uwsgi to deploy the django project according to the tutorial. Listening to port 8000 is normal. When accessing port 80, 404 not found is displayed.
The django project directory is /home/wu/Documents/env/myblog
Document structure under the project folder

myblog_nginx.confFile

# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/wu/Documents/env/myblog/mysite.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name .example.com; # substitute your machine's IP address or FQDN
    charset     utf-8;
    # max upload size
    client_max_body_size 75M;   # adjust to taste
    # Django media
    location /media  {
        alias /home/wu/Documents/env/myblog/media;  # your Django project's media files - amend as required
    }
    location /static {
        alias /home/wu/Documents/env/myblog/static; # your Django project's static files - amend as required
    }
    # Finally, send all non-media requests to the Django server.
    location / {
    root /home/wu/Documents/env/myblog;
        uwsgi_pass  django;
        include     /home/wu/Documents/env/myblog/uwsgi_params; # the uwsgi_params file you installed
    }
}

mysite_uwsgi.iniFile

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/wu/Documents/env/myblog
# Django's wsgi file
module          = myblog.wsgi
# the virtualenv (full path)
home            = /home/wu/Documents/env

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /home/wu/Documents/env/myblog/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true

myblog_nginx.confThere is no problem when the file is changed to port 8000

After changing to port 80, raload, restart nginx, uwsgi --ini mysite_uwsgi.ini, and then visit

Port status:

Please give me some advice, I haven’t solved this problem for a long time, I would be very grateful! ! !

伊谢尔伦伊谢尔伦2753 days ago604

reply all(5)I'll reply

  • 高洛峰

    高洛峰2017-05-16 17:13:06

    Has your problem been solved?

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:13:06

    Please tell me how to deploy it, please write a tutorial. .

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:13:06

    The page displayed on port 8000 is the test page that comes with Django. It should not appear when deployed on port 80. It is recommended that you write a page yourself and deploy it to port 80 to try it

    reply
    0
  • PHPz

    PHPz2017-05-16 17:13:06

    Did you configure it elsewhere

    server {
        listen      80;
        xxx
    }
    #导致没进入你的server块,看下nginx.conf,或者其他虚拟主机的配置文件。
    
    另外你的
    server {
        /*这个去掉吧,或者你可以测试重复,host配置一个xxx.com,
        这边也配置为xxx.com,相比于listen 80,会优先进入这个server块。*/
        #server_name .example.com;
    }

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-16 17:13:06

    The location configuration in nginx includes uwsgi_params; you don’t have uwsgi_pass 127.0.0.1:8000;

    reply
    0
  • Cancelreply