linux安装nginx配置https:
安装nginx前需要安装g++、gcc、openssl-devel、pcre-devel和zlib-devel等软件:
1、 yum install gcc-c++ #nginx是C语言开发的,在官网上下的源码需要编译,依赖gcc环境。
2、 yum install -y pcre pcre-devel #pcre是一个Perl库,包括Perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式 。
3、 yum install -y zlib zlib-devel #zlib库提供了很多压缩和解压缩的方式,nginx用zlib对http包进行gzip。
4、 yum install -y openssl openssl-devel #openssl是一个安全套接字层密码库,nginx支持http协议和https协议(在ssl协议上传输http)。
安装ngin地址:/usr/local/nginx
nginx的源码地址:usr/local/nginx-1.8.0
一般nginx都是安装在/usr/local/,所以进入local目录下 cd /usr/local/
5、 wget http://nginx.org/download/nginx-1.8.0.tar.gz
6、 tar -zxvf nginx-1.8.0.tar.gz #解压压缩文件。
7、 cd nginx-1.8.0
8、./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module #如果不加 --with-http_stub_status_module --with-http_ssl_module,后面配置https的时候会报错。
9、make && make install
10、# yum -y install lrzsz
11、安装后启动
cd /usr/local/nginx/sbin
./nginx -s reload启动
(如果提示“nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)”则执行/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf )
ps -e | grep nginx查看80端口
netstat -ltunp查看运行使用的端口
开始配置https了
进入nginx安装目录 cd /usr/local/nginx/conf/nginx.conf
去掉注释
server {
listen 443 ssl;
server_name abc.51js.net.cn; #访问的地址
ssl_certificate /https/1_abc.51js.net.cn_bundle.crt; #上传的CA证书
ssl_certificate_key /https/2_abc.51js.net.cn.key; #密钥
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}