nginx+django+uwsgi+https 配置问题点

- ssl 证书申请

申请域名的网站申请下载对应文件即可

 

- nginx  配置 https

[root@VM_2_29_centos conf]# nginx -t
nginx: [emerg] unknown directive "ssl_certificate" in /usr/local/nginx/conf/nginx.conf:128
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
原因:安装 nginx 的时候未将 ssl 模块编译进 nginx 得重新编译安装
[root@VM_2_29_centos conf]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[root@VM_2_29_centos conf]# make && make install 
 
查看 nginx 安装的模块:

[root@VM_2_29_centos ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

nginx.conf

[root@VM_2_29_centos ~]# cat /usr/local/nginx/conf/nginx.conf
 
#user nobody;
user root;
worker_processes 1;
 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
 
#pid logs/nginx.pid;
 
 
events {
worker_connections 1024;
}
 
 
http {
include 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 logs/access.log main;
 
sendfile on;
#tcp_nopush on;
 
#keepalive_timeout 0;
keepalive_timeout 65;
 
#gzip on;
 
# http server 80 
server {
listen 80;
server_name zhuoqun.info;
charset utf-8;
rewrite ^(.*) https://$host$1 permanent;  # 实现80端口进来的请求,重定向为https了
# ssl on;
# ssl_certificate /root/yzq/configs/1_zhuoqun.info_bundle.crt;
# ssl_certificate_key /root/yzq/configs/2_zhuoqun.info.key;
# ssl_session_timeout 5m;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #按照这个套件配置
# ssl_prefer_server_ciphers on;
 
 
#charset koi8-r;
 
#access_log logs/host.access.log main;
access_log /root/yzq/logs/host.access.log;
error_log /root/yzq/logs/host.error.log;
 
 
location /media {
alias /root/yzq/djangos/blog/media;
 
}
 
location /static {
alias /root/yzq/djangos/blog/static_root;
 
}
 
location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
#root html;
#index index.html index.htm;
}
 
#error_page 404 /404.html;
 
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
 
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
 
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
 
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
 
 
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
 
# location / {
# root html;
# index index.html index.htm;
# }
#}
 
 
# HTTPS server 443
#
server {
listen 443;
server_name zhuoqun.info;
charset utf-8;
 
ssl on;
ssl_certificate /root/yzq/configs/1_zhuoqun.info_bundle.crt;
ssl_certificate_key /root/yzq/configs/2_zhuoqun.info.key;
 
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
 
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
 
access_log /root/yzq/logs/host.access.log;
error_log /root/yzq/logs/host.error.log;
 
location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
# root html;
# index index.html index.htm;
}
 
location /media {
alias /root/yzq/djangos/blog/media;
}
 
location /static {
alias /root/yzq/djangos/blog/static_root;
}
 
}
 
}
原文地址:https://www.cnblogs.com/yinzhuoqun/p/9364804.html