nginx网站开启https访问,http自动跳转到https
来源:互联网 发布:wdcp数据库备份在哪里 编辑:程序博客网 时间:2024/05/16 14:12
最近nginx要开启https访问,希望服务器与客户端之间传输内容是加密的,防止中间监听泄露信息,下面是颁发证书和配置过程。
安装了openssl和openssl-devel
#yum install openssl
#yum install openssl-devel
然后就是自己颁发证书给自己
#cd /usr/local/nginx/conf (自己的配置文件目录)
#openssl genrsa -des3 -out server.key 1024
#openssl req -new -key server.key -out server.csr
#openssl rsa -in server.key.org -out server.key
#openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
至此证书已经生成完毕,下面就是配置nginx
server {
listen 443;
ssl on;
ssl_certificate /usr/local/nginxtest/conf/sites/server.crt;
ssl_certificate_key /usr/local/nginxtest/conf/sites/server.key;
控制面板 -> Internet选项 -> 内容 -> 发行者 -> 受信任的根证书颁发机构 -> 导入 -》选择server.crt
完整nginx配置文件
server {
listen 82;
server_name *.域名;
rewrite ^(.*) https://$host$1 permanent;
# PATH:/usr/local/nginxtest/conf/sites/ind.conf
listen 444;
charset utf-8;
server_name *.域名;
root /usr/local/nginxtest/ana/public;
index index.html index.htm index.php;
client_max_body_size 4m;
error_log /tmp/nginx_ind_error.log;
access_log /tmp/nginx_ind_access.log;
# ssl
ssl on;
ssl_certificate /usr/local/nginxtest/conf/sites/server.crt;
ssl_certificate_key /usr/local/nginxtest/conf/sites/server.key;
# 开启gzip
gzip on;
gzip_min_length 5k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 3;
gzip_types text/plain application/json application/javascript text/css application/xml text/javascript image/jpeg image/gif image/png;
gzip_vary on;
# 压缩资源不存在
if (!-f $request_filename) {
rewrite ^/dest/(.*)$ /static/$1 break;
}
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTPS on;
}
}
安装了openssl和openssl-devel
#yum install openssl
#yum install openssl-devel
然后就是自己颁发证书给自己
#cd /usr/local/nginx/conf (自己的配置文件目录)
#openssl genrsa -des3 -out server.key 1024
#openssl req -new -key server.key -out server.csr
#openssl rsa -in server.key.org -out server.key
#openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
至此证书已经生成完毕,下面就是配置nginx
server {
listen 443;
ssl on;
ssl_certificate /usr/local/nginxtest/conf/sites/server.crt;
ssl_certificate_key /usr/local/nginxtest/conf/sites/server.key;
}
然后重启nginx即可。
问题:
让浏览器信任自己颁发的证书,具体方法:
控制面板 -> Internet选项 -> 内容 -> 发行者 -> 受信任的根证书颁发机构 -> 导入 -》选择server.crt
完整nginx配置文件
server {
listen 82;
server_name *.域名;
rewrite ^(.*) https://$host$1 permanent;
}
#访问http82端口的时候自动跳转到https
# PATH:/usr/local/nginxtest/conf/sites/ind.conf
listen 444;
charset utf-8;
server_name *.域名;
root /usr/local/nginxtest/ana/public;
index index.html index.htm index.php;
client_max_body_size 4m;
error_log /tmp/nginx_ind_error.log;
access_log /tmp/nginx_ind_access.log;
# ssl
ssl on;
ssl_certificate /usr/local/nginxtest/conf/sites/server.crt;
ssl_certificate_key /usr/local/nginxtest/conf/sites/server.key;
# 开启gzip
gzip on;
gzip_min_length 5k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 3;
gzip_types text/plain application/json application/javascript text/css application/xml text/javascript image/jpeg image/gif image/png;
gzip_vary on;
# 压缩资源不存在
if (!-f $request_filename) {
rewrite ^/dest/(.*)$ /static/$1 break;
}
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTPS on;
}
}
参考:
http://www.cnblogs.com/yun007/p/3739182.html
http://blog.csdn.net/kongqz/article/details/9250689
http://www.cnblogs.com/tintin1926/archive/2012/07/12/2587311.html
0 0
- nginx网站开启https访问,http自动跳转到https
- 使用nginx实现http访问自动跳转到https端口
- nginx 配置https访问以及访问http跳转到https
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https) mark
- tomcat设置https访问(http自动跳转到https)
- tomcat设置https访问(http自动跳转到https)
- Tomcat配置HTTPS及访问HTTP自动跳转到HTTPS
- nginx http 跳转到https
- Nginx开启https访问
- Nginx配置http强制跳转到https
- Nginx跳转任意Http请求到Https
- Git客户端图文详解如何安装配置GitHub操作流程攻略
- VB
- [MySQL]快速解决"is marked as crashed and should be repaired"故障
- HDU3466(01背包)
- 使用uiautomatorviewer获取android apk的元素
- nginx网站开启https访问,http自动跳转到https
- 简单数的乘法结果
- WebView 读取 数据
- 刻录光盘(图论基础)
- 10的阶乘
- BFS 搜索 Problem 1013 A strange lift
- 计算机图形学(二)输出图元_1_OpenGL画点函数
- TCP/IP详解学习笔记(5)-IP选路,动态选路,和一些细节
- 输出最大和第二大的数