簡體   English   中英

Nginx和uWSGI的內部服務器錯誤

[英]Internal Server Error with Nginx and uWSGI

我正在嘗試在Linode.com上使用Nginx托管應用程序,但在uWSGI配置上卻停留得很早。

我已經使用了“入門”指南“在Ubuntu 12.04上使用uWSGI和nginx的WSGI(精確的穿山甲)”指南,並且已經成功部署了Nginx(在瀏覽器中獲得了Nginx歡迎消息)。

盡管以上教程適用於Ubuntu 12.04,但我使用的是14.04。

當我開始使用uWSGI配置和“ Hello World” Python應用程序時,問題就開始了。 在瀏覽器中轉到location / ,返回Failed to load resource: the server responded with a status of 500 (Internal Server Error) ,服務器error.log中未記錄任何內容。 雖然location /static可以工作,並且可以毫無障礙地提供文件。

我已經嘗試了很多事情,並廣泛地尋求針對Google和Stackoverflow的修復程序,但一無所獲,現在我有點沮喪。

感謝您的任何幫助。

這是我的配置文件(我已經隱藏了我的域和IP):

/etc/hosts

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

/etc/nginx/sites-enabled/example.com

server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}

/etc/uwsgi/apps-enabled/example.com.xml

<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>

/srv/www/example.com/application/wsgi_configuration_module.py

import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'

last access log

XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"

only error log I've got only one time when trying to fix this

2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"

我不知道/etc/nginx/sites-enabled/dev.host.in是什么? 如何或為什么* .in? 我認為你應該嘗試

step 1.

create project.ini file

# django_project.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/username/django_project
# Django's wsgi file
module          = blog.wsgi
# the virtualenv (full path)
home            = /home/username/Env/project
# process-related settings
master          = true
pidfile         = /tmp/proj_uwsgi.pid
# maximum number of worker processes
processes       = 5
# the socket
socket          = :8001
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum           = true
# background the process
daemonize        = /home/username/django_project/error_uwsgi.log


step 2.

create mysite.conf in nginx, vim /etc/nginx/conf.d/mysite.conf

upstream django {
    #server unix:///home/username/django_project/djproj.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 localhost mysite.com www.mysite.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/username/django_project/media;  # your Django project's media files - amend as required
    }

    location /static {        alias /home/username/django_project/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  127.0.0.1:8001;#project;        
        include     /home/username/django_project/uwsgi_params; # the uwsgi_params file you installed
    }
}



step 3.

ln -s /etc/nginx/uwsgi_params /home/username/django_project/

step 4.

uwsgi --ini django_project.ini

uwsgi --stop /tmp/proj_uwsgi.pid
uwsgi --reload /tmp/proj_uwsgi.pid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM