首頁  >  問答  >  主體

ubuntu16.04 - nginx+uwsgi部署django,8000埠正常,80埠404

依照教學用nginx+uwsgi部署django項目,監聽8000埠正常,80埠存取時顯示404 not found.
django專案目錄為/home/wu/Documents/env/myblog
專案資料夾下文件結構

#myblog_nginx.conf

# 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.ini

# 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.conf檔案中改為8000埠時沒問題

改為80埠後,raload,restart nginx,uwsgi --ini mysite_uwsgi.ini,然後訪問

#連接埠狀態:

求指點,搞了好久都沒解決這個問題,感激不盡! ! !

伊谢尔伦伊谢尔伦2714 天前559

全部回覆(5)我來回復

  • 高洛峰

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

    請問你的問題解決了嗎?

    回覆
    0
  • 淡淡烟草味

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

    請問兄台如何部署,,寫個教學吧。 。

    回覆
    0
  • 仅有的幸福

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

    8000 埠顯示的那個頁面是 Django 自帶的測試頁,在 80 埠部署的時候應該不會出現,建議你自己寫個頁面部署到 80 埠試試

    回覆
    0
  • PHPz

    PHPz2017-05-16 17:13:06

    是不是你其他地方配置了

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

    回覆
    0
  • 天蓬老师

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

    nginx裡面的location配置,include uwsgi_params;後面你沒有uwsgi_pass 127.0.0.1:8000;

    回覆
    0
  • 取消回覆