在linux系统下安装两个nginx以及启动、停止、重起
生活随笔
收集整理的這篇文章主要介紹了
在linux系统下安装两个nginx以及启动、停止、重起
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
如果沒有安裝過nginx請(qǐng)看:linux下nginx部署以及配置詳解
1、第一個(gè)nginx已經(jīng)安裝完成后,現(xiàn)在安裝第二個(gè)nginx
啟動(dòng):sudo /usr/sbin/nginx3 重起:sudo /usr/sbin/nginx3 -s reload 停止:sudo /usr/sbin/nginx3 -s stop一、進(jìn)入nginx目錄進(jìn)行編譯安裝
1、切換目錄:
cd /usr/local/src/nginx-1.16.1 安裝第二個(gè)路徑會(huì)有所不同,我這里安裝的是第三個(gè)nginx3,如果要安裝4個(gè) 就改為nginx4,需要注意nginx.conf不需要改變,命令如下:./configure \ --prefix=/usr/local/nginx3 \ --sbin-path=/usr/sbin/nginx3 \ --conf-path=/etc/nginx3/nginx.conf \ --error-log-path=/var/log/nginx3/error.log \ --http-log-path=/var/log/nginx3/access.log \ --pid-path=/var/run/nginx3.pid \ --lock-path=/var/run/nginx3.lock \ --http-client-body-temp-path=/var/tmp/nginx3/client \ --http-proxy-temp-path=/var/tmp/nginx3/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx3/fcgi \ --http-uwsgi-temp-path=/var/tmp/nginx3/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx3/scgi \ --user=nginx3 \ --group=nginx3 \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module View Code
? 執(zhí)行完后下面就是nginx3的路徑
2、安裝編譯:
make && make installmkdir -pv /var/tmp/nginx3/client
3、添加SysV啟動(dòng)腳本
vi /etc/init.d/nginx3按i進(jìn)入編輯狀態(tài),需要多個(gè)nginx修改以下兩個(gè)路徑即可,如圖
#!/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/nginx3" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx3/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILEretval=$?echo [ $retval -eq 0 ] && touch $lockfilereturn $retval } stop() {echo -n $"Stopping $prog: " killproc $prog -QUITretval=$?echo [ $retval -eq 0 ] && rm -f $lockfilereturn $retval killall -9 nginx } restart() {configtest || return $?stopsleep 1start } reload() {configtest || return $?echo -n $"Reloading $prog: " killproc $nginx -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" instart)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 View Code?
?
?
4.賦予腳本執(zhí)行權(quán)限
chmod +x /etc/init.d/nginx38.添加nginx服務(wù)進(jìn)程用戶
groupadd -r nginx3useradd -r -g nginx nginx3
9、添加至服務(wù)管理列表,設(shè)置開機(jī)自啟
chkconfig --add nginx3chkconfig nginx3 on
?10、修改nginx.conf端口號(hào),我這里改為81
vi /etc/nginx3/nginx.conf?
?11、啟動(dòng)nginx3
/usr/sbin/nginx3查看端口號(hào)
netstat -lntp
?
?
?
?
?11、在啟動(dòng)一個(gè)nginx
?
?
?12、停止nginx3
sudo /usr/sbin/nginx3 -s stop?
轉(zhuǎn)載于:https://www.cnblogs.com/weibanggang/p/11487339.html
總結(jié)
以上是生活随笔為你收集整理的在linux系统下安装两个nginx以及启动、停止、重起的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下nginx部署以及配置详解
- 下一篇: linux权限管理(chown、chgr