nginx 安装(支持https 多域名证书+支持TCP端口转发)

1、环境准备:先安装准备环境

[root@nginx ~]#yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel  openssl openssl-devel 

 2、下载nginx 安装包:  官网地址:http://nginx.org/

现在就是Nginx和OpenSSL的安装与配置(这里注意,一般情况下一个IP只支持一个SSL证书,那么我们现在要在一个IP上实现多个SSL证书,就必须让Nginx支持TLS SNI,由于默认的OpenSSL是没有打开TLS SNI的),TCP请求转发基于stream在nginx1.9版本前,需要单独编译安装该组建,而目前我下载的是nginx-1.14.0

3、解压安装包:

[root@nginx ~]#tar xvf  nginx-1.14.0.tar.gz

[root@nginx ~]#cd nginx-1.14.0

[root@nginx ~]#groupadd nginx

[root@nginx ~]#useradd -g nginx nginx

[root@nginx ~]#./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

[root@nginx ~]#make && make install

[root@nginx ~]#cd /usr/local/nginx/sbin

[root@nginx ~]#./nginx -V

[root@nginx ~]#

Nginx 启动脚本

#!/bin/bash  
#chkconfig: - 85 15  
#description: Nginx is a World Wide Web server.  
#processname: nginx  
nginx=/usr/local/nginx/sbin/nginx  
conf=/usr/local/nginx/conf/nginx.conf  

case $1 in  
       start)  
              echo -n "Starting Nginx"  
              $nginx -c $conf  
              echo " done"  
       ;;  

       stop)  
              echo -n "Stopping Nginx"  
              killall -9 nginx  
              echo " done"  
       ;;  

       test)  
              $nginx -t -c $conf  
       ;;  

        reload)  
              echo -n "Reloading Nginx"  
              ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP  
              echo " done"  
       ;;  

        restart)  
                $0 stop  
                $0 start  
       ;;  

       show)  
              ps -aux|grep nginx  
       ;;  

       *)  
              echo -n "Usage: $0 {start|restart|reload|stop|test|show}"  
       ;;  esac
chmod +x /etc/init.d/nginx
chkconfig --add nginx  
chkconfig nginx on

服务启动脚本(适合centos 7 版本)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

#vi /lib/systemd/system/nginx.service

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target remote-fs.target nss-lookup.target

  

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx 

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

  

[Install]

WantedBy=multi-user.target

#chmod +x /lib/systemd/system/nginx.service

#systemctl enable nginx.service

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值