导读今天把项目的https配置完成。下面是具体的配置步骤1.下载Linux:CentOS 7.2 64位Nginx:nginx-1.13.1安装目录:/opt/nginx/wget http://nginx.org/download/nginx-1.13.1.tar.gzan2.安装1:安装相关依赖1.gcc、gcc-c

今天把项目的https配置完成。下面是具体的配置步骤

1.下载

Linux:CentOS 7.2 64位

Nginx:nginx-1.13.1

安装目录:/opt/nginx/

wget http://nginx.org/download/nginx-1.13.1.tar.gzan

2.安装

1:安装相关依赖

1.gcc、gcc-c++
yum install gcc 
yum install gcc-c++
2.pcre 、zilb
yum -y install pcre*
yum -y install zlib*
3.因为这次主要是配置https所以添加openssl
yum -y install openssl 
yum -y install openssl-devel

2、安装Nginx

(1) 解压安装包

tar -z -xv -f nginx-1.13.1.tar.gz

(2) 编译

cd nginx-1.13.1 #进入nginx
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre
参数说明:
--prefix:设置安装路径 
--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-pcre:为了支持rewrite重写功能,必须制定pcre

(3) 安装

make 
make install

(4) 启动

/opt/nginx/sbin/nginx -c /opt/nginx/nginx-1.13.1/conf/nginx.conf

(5) 页面

访问 http://域名/

腾讯云 nginx服务器安装,配置https证书

三、配置文件

这一步最重要,上面的按照顺寻安装基本上都没有什么问题


#user nobody;
worker_processes 1;
events {
 worker_connections 1024;
}
http {
 include mime.types;
 default_type application/octet-stream;
 
 sendfile on;
 #tcp_nopush on;
 #keepalive_timeout 0;
 keepalive_timeout 65;
 #gzip on;
 server {
 listen 80;
 server_name www.whfrecord.com; # 域名配置
	rewrite ^(.*)$ https://$host$1 permanent; # 默认强制使用https对http进行跳转
 #charset koi8-r;
 #access_log logs/host.access.log main;
 location / {
 root html;
 index index.html index.htm;
 }
 
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }
 
 }
 server {
 listen 443 ssl;
 server_name www.whfrecord.com;
 ssl_certificate /home/key_dir/1_www.whfrecord.com_bundle.crt; # 指定对应的证书
 ssl_certificate_key /home/key_dir/2_www.whfrecord.com.key; # 指定对应的私钥
 ssl_session_cache shared:SSL:1m;
 ssl_session_timeout 5m;
 ssl_ciphers HIGH:!aNULL:!MD5;
 ssl_prefer_server_ciphers on;
 location / {
 proxy_pass http://127.0.0.1:port/; # 将请求都代理到本机port,这里配置的是项目本地的ip:port 访问域名后会跳转到这个地址里
	}
 }
}

主要有两个地方

 listen 80; 端口的监听
listen 443 ssl; 443端口的监听

这两个地方配置的地方修改成功后,在访问就会是https请求