问题描述
发生了什么事情是应用程序确实做出响应,并将其重定向到https,这是一个奇怪的问题,一个叫做satchmo的django项目,我使用nginx和uwsgi进行部署。然后到http并返回https直到nginx停止,应用程序从不响应。
帮我弄清楚这一点。谢谢!
这是我的网站可用的nginx配置文件:
server {
listen 80;
server_name miche.maumercado.com;
重写^ https:// $ server_name $ request_uri?常驻;
}
server {
listen 443;
charset utf-8;
server_name miche.maumercado.com;
ssl on;
ssl_certificate /home/ubuntu/test.pem;
ssl_certificate_key / home / ubuntu / cert-EO5rjY;
access_log /home/ubuntu/logs/miche/nginx/access.log;
error_log /home/ubuntu/logs/miche/nginx/error.log;
client_max_body_size 100m;
位置^〜/ static / {
alias / home / ubuntu / django-projects / miche_store / static-collect /;
expires max;
}
位置^〜/ media / {
别名/ home / ubuntu / django-projects / miche_store / media /
expires max;
}
位置/ {
uwsgi_pass unix:/tmp/uwsgi_miche.sock;
包含/ etc / nginx / uwsgi_params;
}
}
这是uwsgi.conf文件在/ etc / init中:
#file:/etc/init/uwsgi_miche.conf
描述uWSGI starter
开始(本地文件系统和运行级别[2345])
在运行级别停止
respawn
#home - 是我们的virtualenv目录的路径
#pythonpath - 我们的django应用程序的路径
#module - wsgi处理程序python脚本
exec / home / ubuntu / ve / miche_store / bin / uwsgi \
--uid ubuntu \
--pythonpath / home / ubuntu / django-projects / miche_store \
-H / home / ubuntu / ve / miche_store \
--socket /tmp/uwsgi_miche.sock \
--chmod-socket 644 \
- 模块wsgi \
--logdate \
- 优化2 \
--processes = 6 \
--max-requests = 5000 \
--master \
--vacuum \
--logto /home/ubuntu/logs/miche/uwsgi.log
and heres我的wsgi.py文件:
import os
import sys
import site
site.addsitedir('/ home / ubuntu / ve / miche_store / lib / python2.6 / site-packages')
sys.path.append(os.path.abspath(os.path.dirname(__ file__ )))
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__ file__)),'../'))
os.environ ['DJANGO_SETTINGS_MODULE'] ='miche_store.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
感谢大家的帮助!
Satchmo包括一个名为 satchmo_store.shop.SSLMiddleware.SSLRedirect
的中间件,它自动重定向到站点的SSL /非SSL部分。如果您希望通过SSL进行服务,您必须设置通过SSL提供的URL,否则中间件将重定向到非SSL页面。从文档中:
在您的情况下,由于您通过SSL提供整个站点,您可能只需在 settings.py
中禁用该中间件,档案。
Im having a weird issue with a django project called satchmo, Im deploying with nginx and uwsgi.
Whats happening is that the application does respond and it redirects to https and then to http and back to https until nginx stops and the application never responds.
Help me figure out this. Thank you!
this is my sites-available config file for nginx:
server {
listen 80;
server_name miche.maumercado.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
charset utf-8;
server_name miche.maumercado.com;
ssl on;
ssl_certificate /home/ubuntu/test.pem;
ssl_certificate_key /home/ubuntu/cert-EO5rjY;
access_log /home/ubuntu/logs/miche/nginx/access.log;
error_log /home/ubuntu/logs/miche/nginx/error.log;
client_max_body_size 100m;
location ^~ /static/ {
alias /home/ubuntu/django-projects/miche_store/static-collect/;
expires max;
}
location ^~ /media/ {
alias /home/ubuntu/django-projects/miche_store/media/;
expires max;
}
location / {
uwsgi_pass unix:/tmp/uwsgi_miche.sock;
include /etc/nginx/uwsgi_params;
}
}
This is the uwsgi.conf file in /etc/init:
# file: /etc/init/uwsgi_miche.conf
description "uWSGI starter"
start on (local-filesystems and runlevel [2345])
stop on runlevel [016]
respawn
# home - is the path to our virtualenv directory
# pythonpath - the path to our django application
# module - the wsgi handler python script
exec /home/ubuntu/ve/miche_store/bin/uwsgi \
--uid ubuntu \
--pythonpath /home/ubuntu/django-projects/miche_store \
-H /home/ubuntu/ve/miche_store \
--socket /tmp/uwsgi_miche.sock \
--chmod-socket 644 \
--module wsgi \
--logdate \
--optimize 2 \
--processes=6 \
--max-requests=5000 \
--master \
--vacuum \
--logto /home/ubuntu/logs/miche/uwsgi.log
And heres my wsgi.py file:
import os
import sys
import site
site.addsitedir('/home/ubuntu/ve/miche_store/lib/python2.6/site-packages')
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'miche_store.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Thank you all for your help!
Satchmo includes a piece of middleware called satchmo_store.shop.SSLMiddleware.SSLRedirect
, which automatically does redirecting to SSL/non-SSL portions of the site. You have to set up URLs to be served via SSL if you want them to be served via SSL, otherwise the middleware redirects to a non-SSL page. From the docs:
In your case, since you're serving the entire site via SSL, you can probably just disable that middleware in your settings.py
file.
这篇关于satchmo nginx重定向到https,然后再http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!