用nginx和gunicorn设置Django我已经能够提供静态文件,但带来了Django的502。 该网站运行没问题runserver 0.0.0.0:8000我也曾在uwsgi之前,我不认为这两个(gunicorn和uwsgi)是冲突然而。 当我运行gunicorn状态检查我得到 ubuntu@ip-172-31-16-133:~$ sudo systemctl status gunicorn ● gunicorn.service – gunicorn daemon Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2017-01-31 10:36:23 UTC; 4min 20s ago Process: 32261 ExecStart=/home/ubuntu/djangoenv/bin/gunicorn –workers 10 –bind unix:/home/ubu Main PID: 32261 (code=exited, status=203/EXEC) Jan 31 10:36:23 ip-172-31-16-133 systemd[1]: Started gunicorn daemon. Jan 31 […]
我想为nginx设置ssl,我的项目是django,我也使用gunicorn作为wsgi http服务器。 我在settings.py代码中添加以下几行代码: CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True 我不知道是否有必要这样做,然后我configuration我的nginx在以下forms: upstream app_server { server 127.0.0.1:6000; // your gunicorn server } server { listen 80; server_name <name>; return 301 https://$host$request_uri; } server { #listen 80; listen 443 default ssl; client_max_body_size 4G; server_name <name>; #ssl on; ssl_certificate /etc/nginx/ssl/ssl.crt; ssl_certificate_key /etc/nginx/ssl/ssl.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers […]
我请求一些JSON数据的一些url,有时它工作正常,有时并不…我看了这里的另一个相关的提示,但似乎build议不要改变内容长度的中间件…我的JSON数据不完整是图像下面显示: 我的应用程序nginxconfiguration: server { listen 80; server_name myapp.com; access_log /var/log/nginx/myapp_access.log; error_log /var/log/nginx/myapp_error.log; location / { client_max_body_size 400M; proxy_read_timeout 120; proxy_connect_timeout 120; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Client-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://127.0.0.1:8888; } } gunicorn脚本: #!/bin/bash set -e DJANGODIR=/home/ubuntu/apps/myapp LOGFILE=/var/log/gunicorn/myapp.log LOGDIR=$(dirname $LOGFILE) NUM_WORKERS=3 # user/group to run as USER=ubuntu GROUP=ubuntu cd /home/ubuntu/apps/myapp […]
我在数字海洋液滴上运行gunicorn和nginx。 我面临的问题是,我的这些服务的configuration文件是 /etc/nginx/sites-enabled/django 和 /etc/init/gunicorn.conf 而我的代码是在/src/my_project 我的问题是,我的源代码是在源代码pipe理下。 /etc/中的configuration文件不是。 这个问题, 你如何处理源代码pipe理中的configuration文件? ,说你应该保持你的configuration文件在源代码控制,但它不解释如何configuration它们。 如何将我的nginx和gunicornconfiguration文件包含在我的django项目的其余部分的源代码控制中,同时仍然将configuration文件保存在服务器上的nginx和gunicorn? 谢谢!
我正在尝试按照这个数字海洋教程服务一个简单的API。 为了testing,我早些时候通过使用gunicorn服务API $ gunicorn –bind 0.0.0.0:5000 trumporate.wsgi:app 并且将API端点限制在ec2框中 $ curl -X GET http://0.0.0.0:5000/api/v1/trump/rant/ { "foo": "bar" } 现在我把这个gunicorn进程转到启动时运行一个systemd服务 # /etc/systemd/system/trumporate.service [Unit] Description=Gunicorn instance for trumporate After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/var/opt/trumporate ExecStart=/usr/local/bin/gunicorn –workers 3 –bind unix:trumporate.sock -m 007 –access-logfile /var/log/trumporate/gunicorn-access.log –error-logfile /var/log/trumporate/gunicorn-error.log trumporate.wsgi:app [Install] WantedBy=multi-user.target 我已经创build了这些文件 /var/log/trumporate/gunicorn-error.log /var/log/trumporate/gunicorn-access.log 并将所有权和组更改为ubuntu 启用服务并重新启动后,我检查了状态 $ sudo systemctl status trumporate.service ● […]
我一直在努力解决这个问题两天没有成功。 我创build了一个名为“testdj”的默认Django(1.6.1)应用程序实例,将其安装在运行Ubuntu Server 13.10的Amazon AWS EC2 t1.micro实例上,并试图访问默认的Django“It works !” 通过Gunicorn页(第18节)。 当我从命令行启动gunicorn时: gunicorn testdj.wsgi:application –bind [ec2-public-dns]:8001 当我input这个url时,我可以看到页面: http://[ec2-public-dns]:8001 然而,如果我使用了一个在读完Karzynski的博文“用Nginx,Gunicorn,virtualenv,supervisor和PostgreSQL设置Django”之后创build的“start-gunicorn”bash脚本,我总是会遇到一个错误。 当我input这个url… http://[ec2-public-dns] …我得到这个错误: Error 502 – Bad Request The server could not resolve your request for uri: http://[ec2-public-dns] 这是开始gunicorn脚本: #!/bin/bash NAME="testdj" DJANGODIR=/usr/share/nginx/html/testdj SOCKFILE=/usr/share/nginx/html/testdj/run/gunicorn.sock USER=testdj GROUP=testdj NUM_WORKERS=3 DJANGO_SETTINGS_MODULE=testdj.settings DJANGO_WSGI_MODULE=testdj.wsgi WORKON_HOME=/home/testdj/venv source `which virtualenvwrapper.sh` workon $NAME export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE export […]
我尝试使用nginx,gunicorn和virtualenv部署我的Django项目。 但即时通讯运行此评论时得到以下错误 sudo gunicorn_django –bind test.com:8001 日志: Traceback (most recent call last): File "/opt/postjust/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker worker.init_process() File "/opt/postjust/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process self.wsgi = self.app.wsgi() File "/opt/postjust/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/opt/postjust/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 105, in load mod = util.import_module("gunicorn.app.django_wsgi") File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/opt/postjust/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", […]
我有以下问题,我试图把一个Django应用程序与运行Nginx的VPS上的一个gunicorn服务器。 我的nginxconfiguration如下所示: upstream app_name { server unix:/path/to/socket/file.sock fail_timeout=10; } server { listen 80 default_server; listen[::]:80 default_server ipv6only=on; root /webapps/; server_name my_hostname.com; location / { proxy_set_header Host $http_host; } location /appname/ { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_name; } } 但是,当我导航到my_server.com/appname/我不断得到404错误。 对于Nginx来说,我还是个新手,有人能指出我如何设置/appname/ path的proxy_pass方向吗? 我应该指出,当/appname/位置replace为/ django应用程序运行正常。
我想在我的根目录public_html有一个静态网站,然后Flask应用程序在他们自己的子目录(例如public_html /富)。 静态根目录function按预期。 我花了好几个小时编辑nginxconfiguration来让Flask应用程序工作,但是总是返回到同一个地方,即当我迁移到mysite / foo时,下面的代码总是返回'Bad Config'。 我希望它返回“Hello World!” 如果我改变了nginx的configuration,使得服务器的根目录在public_html / foo中,那么Flask应用程序按预期工作(即mysite.com返回“Hello World!”)。 在下面的configuration中,当我认为它应该指向mysite.com/foo时,Flask索引仍然指向mysite.com 在/ etc / nginx的/启用的站点 – / mysite的 upstream frontends { # gunicorn server 127.0.0.1:18000; } server { listen 80; server_name www.mysite.com; rewrite ^/(.*) http://mysite.com$1 permanent; } server { listen 80; server_name mysite.com; server_name_in_redirect off; root /home/ubuntu/public_html/mysite; access_log /home/ubuntu/logs/mysite/access.log; error_log /home/ubuntu/logs/mysite/error.log; location […]
我只是用Nginx(反向代理)为Django web应用程序设置了Gunicorn。 根据gunicorn.log这个组合似乎正确地gunicorn.log 。 请注意,我没有使用主pipe。 但奇怪的是,我的环境variables (在.profile设置)根本没有被拾起! printenv显示他们存在。 我试过的一些东西是把环境variables放在/etc/default/nginx然后重新启动nginx, etc/environment , .profile , nginx.conf , gunicorn.conf等等。 顺便说一下,它安装和configurationnginx 之前完美的工作,即当我只是运行: gunicorn –bind 0.0.0.0:8080 –env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi:application 。 现在看来,nginx: 除了TZvariables外,删除从其父进程inheritance的所有环境variables 资料来源: http : //nginx.org/en/docs/ngx_core_module.html#env难道这就是为什么我没有试图接近工作? 但是如果是这样的话,那么添加到nginx.conf中的这些variables应该已经被提取出来了。 不过,使用echo $envvar在命令行上产生正确的值,这告诉我可能已经设置了这些variables,但是被绕过或忽略了 。 请注意, USER envvariables也显示为None ,而打印TERM打印linux 。 wsgi.py : import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") from django.core.wsgi import get_wsgi_application from dj_static import Cling application […]