centos7下nginx-1.18.0安装

1、下载安装包

进入官网(http://nginx.org/en/download.html)下载指定版本的安装包,这里下载的是最新的nginx-1.18.0.tar.gz:

1 http://nginx.org/download/nginx-1.18.0.tar.gz

2、解压压缩文件

将下载下来的压缩文件进行解压安装:

1 [develop@fxb-ah softs]$ tar zxf nginx-1.18.0.tar.gz
2 [develop@fxb-ah softs]$ cd nginx-1.18.0

3、编译安装nginx

3.1 环境的安装

安装nginx之前,需要安装相应的环境,让nginx可以正常的允许:

  • gcc环境:基本运行环境
  • pcre:用于nginx的http模块解析正则表达式
  • zlib:用户进行gzip压缩
  • openssl:用于nginx https协议的传输

直接通过yum进行安装即可:

1 [develp@fxb-ah nginx-1.18.0]$ sudo yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

 3.2 编译安装nginx

 1 [develop@fxb-ah nginx-1.18.0]$ sudo useradd -M -s /sbin/nologin nginx
 2 [develop@fxb-ah nginx-1.18.0]$ sudo ./configure --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --prefix=/usr/local/nginx --user=nginx
 3 [develop@fxb-ah nginx-1.18.0]$ sudo make && sudo make install
 4 [develop@fxb-ah nginx-1.18.0]$ cd /usr/local/nginx/
 5 [develop@fxb-ah nginx]$ ll
 6 total 16
 7 drwxr-xr-x 2 root root 4096 Jun 30 14:21 conf
 8 drwxr-xr-x 2 root root 4096 Jun 30 14:21 html
 9 drwxr-xr-x 2 root root 4096 Jun 30 14:21 logs
10 drwxr-xr-x 2 root root 4096 Jun 30 14:21 sbin

安装完成!

 4、设置服务

将nginx制作成服务,并设置开机启动(centos7):

 1 [develop@fxb-ah nginx]$ sudo vim /usr/lib/systemd/system/nginx.service
 2 [Unit]
 3 Description=nginx
 4 After=network.target
 5 
 6 [Service]
 7 Type=forking
 8 ExecStart=/usr/local/nginx/sbin/nginx
 9 ExecReload=/usr/local/nginx/sbin/nginx -s reload
10 ExecStop=/usr/local/nginx/sbin/nginx -s quit
11 PrivateTmp=true
12 
13 [Install]
14 WantedBy=multi-user.target
15 [developer@iZuf6ai62xce7yu53epv2jZ redis-6.0.5]$ sudo systemctl daemon-reload
16 [developer@iZuf6ai62xce7yu53epv2jZ redis-6.0.5]$ sudo systemctl start nginx.service
17 [developer@iZuf6ai62xce7yu53epv2jZ redis-6.0.5]$ sudo  systemctl enable nginx.service

 低版本centos下服务制作:

 1 [develop@fxb-ah nginx]$ sudo vi /etc/init.d/nginx
 2 #!/bin/bash
 3 # nginx Startup script for the Nginx HTTP Server
 4 # it is v.0.0.2 version.
 5 # chkconfig: - 85 15
 6 # description: Nginx is a high-performance web and proxy server.
 7 # It has a lot of features, but it's not for everyone.
 8 # processname: nginx
 9 # pidfile: /var/run/nginx.pid
10 # config: /usr/local/nginx/conf/nginx.conf
11 nginxd=/usr/local/nginx/sbin/nginx
12 nginx_config=/usr/local/nginx/conf/nginx.conf
13 nginx_pid=/var/run/nginx.pid
14 RETVAL=0
15 prog="nginx"
16 # Source function library.
17 . /etc/rc.d/init.d/functions
18 # Source networking configuration.
19 . /etc/sysconfig/network
20 # Check that networking is up.
21 [ ${NETWORKING} = "no" ] && exit 0
22 [ -x $nginxd ] || exit 0
23 # Start nginx daemons functions.
24 start() {
25 if [ -e $nginx_pid ];then
26     echo "nginx already running...."
27     exit 1
28 fi
29     echo -n $"Starting $prog: "
30     daemon $nginxd -c ${nginx_config}
31     RETVAL=$?
32     echo
33     [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
34     return $RETVAL
35 }
36 # Stop nginx daemons functions.
37 stop() {
38     echo -n $"Stopping $prog: "
39     killproc $nginxd
40     RETVAL=$?
41     echo
42     [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
43 }
44 # reload nginx service functions.
45 reload() {
46     echo -n $"Reloading $prog: "
47     #kill -HUP `cat ${nginx_pid}`
48     killproc $nginxd -HUP
49     RETVAL=$?
50     echo
51 }
52 # See how we were called.
53 case "$1" in
54 start)
55         start
56         ;;
57 stop)
58         stop
59         ;;
60 reload)
61         reload
62         ;;
63 restart)
64         stop
65         start
66         ;;
67 status)
68         status $prog
69         RETVAL=$?
70         ;;
71 *)
72         echo $"Usage: $prog {start|stop|restart|reload|status|help}"
73         exit 1
74 esac
75 exit $RETVAL
76 [develop@fxb-ah nginx]$ sudo chmod a+x /etc/init.d/nginx
77 [develop@fxb-ah nginx]$ sudo chkconfig --add /etc/init.d/nginx
78 [develop@fxb-ah nginx]$ service nginx status
79 nginx is stopped
80 [develop@fxb-ah nginx]$ sudo chkconfig nginx on

原文链接: https://www.cnblogs.com/springhub/p/13214670.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    centos7下nginx-1.18.0安装

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/360979

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 下午1:35
下一篇 2023年3月2日 下午1:36

相关推荐