【一分钟搞懂;如何通过nginx将网站访问改为https】下面我们通过配置Nginx来开启https访问
1、ssl证书申请可以在阿里云上申请一个免费的需要在域名解析上加上解析值 , 阿里云会自动添加的 。
2、申请完后下载证书放到nginx上/usr/local/nginx/cert/www.suibibk.com.pem;/usr/local/nginx/cert/www.suibibk.com.key;
3、nginx的配置文件如下所示 , 这样就配置好了ssl_certificate/usr/local/nginx/cert/www.suibibk.com.pem;ssl_certificate_key/usr/local/nginx/cert/www.suibibk.com.key;
4、如下nginx配置文件userroot;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events {worker_connections1024;}http {includemime.types;default_typeApplication/octet-stream;#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '#'$status $body_bytes_sent "$http_referer" '#'"$http_user_agent" "$http_x_forwarded_for"';#access_loglogs/access.logmain;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;#gzipon;#1、博客首页server {listen80;server_namewww.suibibk.com suibibk.com;rewrite ^(.*)$ https://$host$1 permanent;}#1、博客首页server {listen 443;server_name www.suibibk.com suibibk.com;#这个是防止登录用suibibk.com , 然后访问用www.suibibk.com,然后session不一致if ( $host = 'suibibk.com' ){rewrite ^(.*)$ https://www.suibibk.com$1 permanent;}ssl on;client_max_body_size 1536m;root html;index index.html index.htm;ssl_certificate/usr/local/nginx/cert/www.suibibk.com.pem;ssl_certificate_key/usr/local/nginx/cert/www.suibibk.com.key;ssl_session_timeout 5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers on;location /fileupload {root/home/itweb/data/;indexindex.html index.htm;}location / {proxy_pass http://127.0.0.1:8080;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Proto https;proxy_next_upstreamoff;proxy_connect_timeout30;proxy_read_timeout1800;proxy_send_timeout300;}}}
推荐阅读
- 如何选择笔记本电脑品牌
- 乾坤大挪移,教你如何将程序从一个硬盘移到另一个硬盘
- 为什么音响会有电流声?如何解决?
- 局域网 数据包是如何在以太网中传递的
- 如何防止服务器被入侵?
- 职业教育|对于冷门专业的学生,该如何考取事业单位的工作?这几个方式很好
- 保存金银花茶过期了怎么办,如何保存花草茶
- 如何分辨月季花茶和玫瑰花茶,玫瑰花茶怎么泡
- 被腐蚀的不锈钢表面如何处理?
- 两天的周末时间,如何玩北京?