Centos7 部署Nginx 支持HTTPS

1、安装依赖

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、下载Wget

这里使用wget进行下载,如果未安装Wget请安装:

yum install -y wget

3、下载Nginx并解压至/usr/local/src目录

wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf  nginx-1.10.2.tar.gz
cd nginx-1.10.2/

4、并使用自定义配置

./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 \
--with-http_ssl_module

5、编译安装nginx

make && make install

6、设置nginx开机并启动,添加到系统服务

使用命令“# vi /etc/init.d/nginx”,打开编辑器,输入如下内容

#!/bin/sh  
# chkconfig: 2345 85 15  
# Startup script for the nginx Web Server  
# description: nginx is a World Wide Web server.   
# It is used to serve HTML files and CGI.  
# processname: nginx  
# pidfile: /usr/local/nginx/logs/nginx.pid  
# config: /usr/local/nginx/conf/nginx.conf  
  
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  
DESC="nginx deamon"  
NAME=nginx  
DAEMON=/usr/local/nginx/sbin/$NAME  
SCRIPTNAME=/etc/init.d/$NAME  
  
test -x $DAEMON || exit 0  
  
d_start(){  
  $DAEMON || echo -n "already running"  
}  
  
d_stop(){  
  $DAEMON -s quit || echo -n "not running"  
}  
  
  
d_reload(){  
  $DAEMON -s reload || echo -n "can not reload"  
}  
  
case "$1" in  
start)  
  echo -n "Starting $DESC: $NAME"  
  d_start  
  echo "."  
;;  
stop)  
  echo -n "Stopping $DESC: $NAME"  
  d_stop  
  echo "."  
;;  
reload)  
  echo -n "Reloading $DESC conf..."  
  d_reload  
  echo "reload ."  
;;  
restart)  
  echo -n "Restarting $DESC: $NAME"  
  d_stop  
  sleep 2  
  d_start  
  echo "."  
;;  
*)  
  echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2  
  exit 3  
;;  
esac  
  
exit 0 

7、给脚本添加可执行权限以及设置开机启动

给启动文件添加执行权限

 chmod +x /etc/init.d/nginx  

添加开机自动启动nginx服务

 chkconfig --add nginx

修改服务启动设置

 chkconfig nginx on

显示开机可以自动启动的服务

 chkconfig --list nginx 

8、相关操作命令

nginx作为服务 启动、停止、无间断服务重启操作

service nginx start
service nginx stop
service nginx reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值