您的位置:首页 > 理论基础 > 计算机网络

centos7编译安装nginx及无缝升级https

2017-06-19 15:01 1161 查看
安装依赖:

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx:
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
配置nginx:

1、默认配置

./configure
2、自定义配置

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
编译安装nginx:

make
make install
设置nginx开机并启动:

vi /etc/rc.local
在rc.local文件中写入:

/usr/local/nginx/sbin/nginx
设置启动文件权限:

chmod 755 /etc/rc.local
启动和停止nginx命令:

cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
nginx无缝升级https:

1、查看nginx是否支持ssl:1、查看nginx是否支持ssl:

/usr/local/nginx/sbin/nginx -V
查看 configure arguments 信息中是否包含 -with-http_ssl_module 字样,如果没有则需要重新编译。找到之前安装 Nginx 时的编译目录,配置ssl模块:

./configure --with-http_ssl_module
make
2、因为这次是升级nginx,所以不需要执行 make install,首先备份原nginx执行脚本:

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old


3、把新编译的nginx执行脚本拷贝到相应的目录下:

cd objs/
cp nginx /usr/local/nginx/sbin/
4、最后进行平滑升级

cd ..
make upgrade
5、编辑配置文件

cd /usr/local/nginx/conf
vim nginx.conf
listen       443;
server_name  域名;
index index.html index.htm index.php;
root 项目根路径;

ssl on;
ssl_certificate 证书路径及文件;
ssl_certificate_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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息