安装nignx1.14,并且打补丁,反向代理健康监控,ssl
作者:互联网
//安装git,下载check_module的健康模块
yum install git git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
// 上传并下载nginx源码,解压 tar xvf nginx-1.14.2.tar.gz
// 安装打补丁的工具 yum -y install patch
// 进入nginx源码目录,第一层
cd nginx-1.14.2
//打源码补丁
patch -p1 </root/nginx_upstream_check_module/check_1.14.0+.patch
// 以下为编译nginx所需的lib yum install gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel cd nginx-1.14.2
// 配置,安装目录为 /usr/nginx ,add-module 的目录为上面git后的目录 ./configure --prefix=/usr/nginx --with-http_ssl_module --add-module=/root/nginx_upstream_check_module/ make install
cd /usr/nginx cd sbin ./nginx
配置反向代理
建立upstream
upstream yiwiki { server 127.0.0.1:8080; server 112.126.56.244; check interval=3000 rise=2 fall=5 timeout=2000 type=http; check_http_expect_alive http_2xx http_3xx; }
配置server 80口
server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
配置443 ssl口
server { listen 443 ssl; server_name localhost;
# 在conf目录建立cert目录,拷贝证书文件至此 ssl_certificate cert/5089556_www.yiwiki.cn.pem; ssl_certificate_key cert/5089556_www.yiwiki.cn.key; # ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; location / { # root html; # index index.html index.htm; proxy_pass http://yiwiki/; } location /status { check_status; } }
停止重启
cd /usr/nginx/sbin ./nginx -s stop ./nginx
建立自启动脚本
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: NGINX is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -n "$user" ]; then if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done fi } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $prog -HUP retval=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
标签:status,nignx1.14,nginx,server,ssl,html,打补丁,echo 来源: https://www.cnblogs.com/sdgtxuyong/p/14335013.html