常用版本分为四大阵营
Nginx 的安装可以选择源码编译的方式也可以使用宝塔面板安装,本文采用的是源码编译安装。
1[root@hadoop100 ~] tar zxvf nginx-1.22.0.tar.gz
1[root@hadoop100 ~] cd nginx-1.21.6
2[root@hadoop100 ~] ./configure --prefix=/usr/local/nginx
3# --prefix=/usr/local/nginx 指安装路径是/usr/local/nginx,如果前面安装了宝塔Linux面板,这一步应该不会出现环境问题。
提示:
1checking for OS
2+ Linux 3.10.0-693.el7.x86_64 x86_64
3checking for C compiler ... not found
4./configure: error: C compiler cc is not found
安装 gcc
1[root@hadoop100 ~] yum install -y gcc
提示:
1/configure: error: the HTTP rewrite module requires the PCRE library.
2You can either disable the module by using --without-http_rewrite_module
3option, or install the PCRE library into the system, or build the PCRE library
4statically from the source with nginx by using --with-pcre=<path> option.
安装 perl 库
1[root@hadoop100 ~] yum install -y pcre pcre-devel
提示:
1./configure: error: the HTTP gzip module requires the zlib library.
2You can either disable the module by using --without-http_gzip_module
3option, or install the zlib library into the system, or build the zlib library
4statically from the source with nginx by using --with-zlib=<path> option.
安装 zlib 库:
1[root@hadoop100 ~] yum install -y zlib zlib-devel
出现这个代表安装成功
1Configuration summary
2 + using system PCRE library
3 + OpenSSL library is not used
4 + using system zlib library
5
6 nginx path prefix: "/usr/local/nginx"
7 nginx binary file: "/usr/local/nginx/sbin/nginx"
8 nginx modules path: "/usr/local/nginx/modules"
9 nginx configuration prefix: "/usr/local/nginx/conf"
10 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
11 nginx pid file: "/usr/local/nginx/logs/nginx.pid"
12 nginx error log file: "/usr/local/nginx/logs/error.log"
13 nginx http access log file: "/usr/local/nginx/logs/access.log"
14 nginx http client request body temporary files: "client_body_temp"
15 nginx http proxy temporary files: "proxy_temp"
16 nginx http fastcgi temporary files: "fastcgi_temp"
17 nginx http uwsgi temporary files: "uwsgi_temp"
18 nginx http scgi temporary files: "scgi_temp"
1[root@centos-linux nginx-1.22.0]# make
2[root@centos-linux nginx-1.22.0]# make install
进入安装好的目录 /usr/local/nginx/sbin
1[root@centos-linux sbin]# ./nginx # 启动
2[root@centos-linux sbin]# ./nginx -s stop #快速停止
3[root@centos-linux sbin]# ./nginx -s quit #优雅关闭,在退出前完成已经接受的连接请求
4[root@centos-linux sbin]# ./nginx -s reload #重新加载配置
关闭防火墙
1[root@hadoop100 ~] systemctl stop firewalld.service
禁止防火墙开机启动
1[root@hadoop100 ~] systemctl disable firewalld.service
放行端口
1[root@hadoop100 ~] firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
1[root@hadoop100 ~] firewall-cmd --reload
创建服务脚本
1[root@hadoop100 ~] vi /usr/lib/systemd/system/nginx.service
服务脚本内容
1[Unit]
2Description=nginx - web server
3After=network.target remote-fs.target nss-lookup.target
4
5[Service]
6Type=forking
7PIDFile=/usr/local/nginx/logs/nginx.pid
8ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
9ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
10ExecReload=/usr/local/nginx/sbin/nginx -s reload
11ExecStop=/usr/local/nginx/sbin/nginx -s stop
12ExecQuit=/usr/local/nginx/sbin/nginx -s quit
13PrivateTmp=true
14
15[Install]
16WantedBy=multi-user.target
重新加载系统服务
1[root@hadoop100 ~] systemctl daemon-reloactdad
启动服务
1[root@hadoop100 ~] systemctl start nginx.service
查看服务是否启动成功
1[root@hadoop100 sbin] systemctl status nginx.service
开机启动
1[root@hadoop100 ~] systemctl enable nginx.service