1. Nginx 配置
/etc/nginx/site-available/mysite
# mysite config
#
upstream mysite
{
server 127.0.0.1:8080;
}
server
{
proxy_redirect off;
include /etc/nginx/proxy_params;
listen 443 ssl; ## listen for ipv4; this line is default and implied
server_name 127.0.0.1;
ssl on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server_nopwd.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location = / {
proxy_pass http://mysite;
}
location ~ /static/ {
root /var/www/mysite/; #static目录在mysite目录下面
expires 30d;
}
location / {
proxy_pass http://mysite;
#proxy_redirect off;
}
#include /etc/nginx/proxy_params;
}
2. mod_wsgi:
sudo apt-get libapache2-mod-wsgi
新建 mysite/mysite/wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
sys.path.append("/var/www/mysite")
mv mysite /var/www/
vim /etc/apache2/site-available/mysite
Listen 8080
<VirtualHost *:8080>
ServerName localhost
ServerAdmin
DocumentRoot /var/www/mysite/mysite
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIScriptAlias / /var/www/mysite/mvsite/wsgi.py
Alias /static /var/www/mysite/static
ErrorLog ${APACHE_LOG_DIR}/mysite.dev.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/mysite.dev.access.log combined
</VirtualHost>
4. sudo a2ensite mysite
sudo service apache2 start
5.记得用https访问站点,至于怎么生成证书,我就不多说了。自己上网去查。
注:可能遇到的问题如下:
1.service apache2 reload ,结果报错:
Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
原因: 没有安装wsgi模块
解决如下:
sudo apt-get install libapache2-mod-wsgi
sudo a2enmod wsgi
service apache2 reload