在nginx上部署Django
嗨,我需要在nginx上部署一个django应用程序。我在fedora中安装了nginx和pythonflup,我尝试了这个,但nginx无法读取我的静态文件。 在我的projectdir中,我使用这个命令来运行fastcgi:在nginx上部署Django,django,deployment,nginx,fastcgi,Django,Deployment,Nginx,Fastcgi,嗨,我需要在nginx上部署一个django应用程序。我在fedora中安装了nginx和pythonflup,我尝试了这个,但nginx无法读取我的静态文件。 在我的projectdir中,我使用这个命令来运行fastcgi: [nima@ca005 bank]$ python ./manage.py runfcgi host=127.0.0.1 port=8080 [nima@ca005 bank]$ 这是我在/etc/nginx/sites enable/中的示例_project.c
[nima@ca005 bank]$ python ./manage.py runfcgi host=127.0.0.1 port=8080
[nima@ca005 bank]$
这是我在/etc/nginx/sites enable/中的示例_project.conf:
server {
listen 80;
server_name 192.168.16.161;
access_log /var/log/nginx/sample_project.access.log;
error_log /var/log/nginx/sample_project.error.log;
# https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
location /static/ { # STATIC_URL
alias /home/nima/workspace/bank/media/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /home/nima/workspace/bank/meli/static/; # MEDIA_ROOT
expires 30d;
}
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8080;
fastcgi_split_path_info ^()(.*)$;
}
}
nginx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enable/*;
}
我该怎么办 首先,如果您选择使用nginx,那么使用
gunicorn
,这是最好的选择,如果您希望使用Apache,那么您可以使用mod_wsgi
将向您展示如何使用gunicorn。为了告诉你它的服务有多好,Instagram使用了gunicorn,因为他们声称它提供了更好的性能
设置gunicorn
非常简单和容易,这里的教程为您提供了使其快速实现所需的一切
是他们的网站。尝试使用fastcgi模式链接或使用uwsgi模式的链路
编辑:django中不推荐使用fcgi模式,将被删除。uwsgi是有利的模式。作为众多参考之一,我使用gunicorn,但当我运行这个命令gunicorn_django-b 0.0.0.0时,它看不到我的静态:8000@nim4n:试试这个:静态部分是的。但我对新贵的部分有一个问题。当我尝试启动服务时,会出现以下错误:root@ca005nima]#服务hello start重定向到/bin/systemctl start hello.service未能发出方法调用:Unit hello.service未能加载:没有这样的文件或目录。有关详细信息,请参阅系统日志和“systemctl status hello.service”。这可能会有所帮助,我编写了一份关于使用upstart、nginx和gunicorn部署Django的指南:gunicorn实际上做了什么?它的作用是什么?