Nginx系列-编译安装
Nginx服务器
1. Nginx是主流的Web服务器,Web服务器在企业应用广泛
2. LNMP架构是创业型企业的主要架构: Nginx+Php- fpm+Mysql
3. Nginx 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。
4. Nginx和Apache相比,nginx的安装、配置、管理等比较方便
Nginx的官网:http://nginx.org/
安装环境
关闭 firewalld
关闭 selinux
系统版本 CentOS Linux release 7.8.2003 (Core
创建nginx系统用户
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -r -g nginx nginx -s /sbin/nologin
[root@localhost ~]# cat /etc/passwd |grep nginx
nginx:x:996:1000::/home/nginx:/sbin/nologin
[root@localhost ~]# id nginx
uid=996(nginx) gid=1000(nginx) 组=1000(nginx)
编译安装
1.安装依赖包
yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
2.下载安装
cd /usr/local/src
wget 'http://nginx.org/download/nginx-1.18.0.tar.gz'
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-pcre
make && make install
#--prefix 指定安装位置
#--with-http_ssl_module https模块
#--with-stream TCP流
#--with-stream_ssl_module tcp-ssl
#--with-http_stub_status_module 监控nginx
#--with-pcre pcre库
安装检查
[root@localhost nginx-1.18.0]# cd /usr/local/nginx/
[root@localhost nginx]# ll
drwxr-xr-x 2 root root 4096 7月 29 19:46 conf #配置文件
drwxr-xr-x 2 root root 38 7月 29 19:46 html #存放网站文件
drwxr-xr-x 2 root root 6 7月 29 19:46 logs #存放日志文件
drwxr-xr-x 2 root root 18 7月 29 19:46 sbin #存放程序
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -V #相关版本信息
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure
arguments: --prefix=/usr/local/nginx --with-http_ssl_module
--with-stream --with-stream_ssl_module --with-http_stub_status_module
--with-pcre
nginx管理
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -t #配置检查
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# /usr/local/nginx/sbin/nginx #启动
[root@localhost nginx]# netstat -tunlp|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6155/nginx: master
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s stop #停止
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s reload #平滑重启
将nginx加入systemctl管理/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
网页打开验证是否正常启动

浙公网安备 33010602011771号