如果没有安装过nginx请看:linux下nginx部署以及配置详解

1、第一个nginx已经安装完成后,现在安装第二个nginx

启动:sudo /usr/sbin/nginx3
重起:sudo /usr/sbin/nginx3 -s reload
停止:sudo /usr/sbin/nginx3 -s stop

一、进入nginx目录进行编译安装

1、切换目录:

cd /usr/local/src/nginx-1.16.
安装第二个路径会有所不同,我这里安装的是第三个nginx3,如果要安装4个 就改为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

执行完后下面就是nginx3的路径

2、安装编译:

make && make install
mkdir -pv /var/tmp/nginx3/client

3、添加SysV启动脚本

vi /etc/init.d/nginx3

按i进入编辑状态,需要多个nginx修改以下两个路径即可,如图

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: -
# 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
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
[ -f $NGINX_CONF_FILE ] || exit
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
killall - nginx
}
restart() {
configtest || return $?
stop
sleep
start
}
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 >&
}
case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
esac

4.赋予脚本执行权限

chmod +x /etc/init.d/nginx3

8.添加nginx服务进程用户

groupadd -r nginx3
useradd -r -g nginx nginx3

9、添加至服务管理列表,设置开机自启

chkconfig --add nginx3
chkconfig nginx3 on

10、修改nginx.conf端口号,我这里改为81

vi /etc/nginx3/nginx.conf

11、启动nginx3

/usr/sbin/nginx3

查看端口号
netstat -lntp

11、在启动一个nginx

12、停止nginx3

sudo /usr/sbin/nginx3 -s stop

最新文章

  1. [收藏]IntelliJ Idea快捷键
  2. div+css背景渐变色代码示例
  3. android开发环境搭建(ubuntu15.04+jdk8+eclipse+android sdk)
  4. Simple Maven Project
  5. UIAlertController弹出提示框
  6. 调研eclipse安卓平台的开发环境
  7. mysql 性能问题
  8. Team Queue
  9. openSession()和getCureentSession()的区别
  10. ffmpeg中ff_scale_image()内存泄露
  11. hdu2457 Trie图+dp
  12. kafka消息中间件及java示例
  13. 抽象工厂模式(Abstract Factory)
  14. WebView的使用--Hybrid App
  15. Chapter 1 Securing Your Server and Network(12):保护链接服务器
  16. Git详解及github与gitlab使用
  17. day13 闭包及装饰器
  18. js实现原生选项卡
  19. LDAP1-安装部署LDAP服务
  20. 【学习总结】Git学习-参考廖雪峰老师教程一-Git简介

热门文章

  1. Linux上DNS解析总是选择resolv.conf中第二位的DNS服务器IP地址
  2. 用JAVA把内存里的二进制文件打包成ZIP包
  3. Python中如何计算字符串里面某一个字符出现的次数?
  4. Cesium原理篇:6 Render模块(6: Instance实例化)【转】
  5. 图片放大神器: waifu2x
  6. 【转载】 TensorFlow函数:tf.Session()和tf.Session().as_default()的区别
  7. JAVA获取树形结构
  8. Mark about 《美国债务危机 》
  9. Windows 10提示你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
  10. 为什么0x00400000是可执行文件的默认基址?EXE base address start with 400000H,Why is 0x00400000 the default base address for an executable?