LNMP:3. CentOS 7 编译安装 Nginx
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。
官网:https://nginx.org
编译安装 Nginx
命令
[rover@localhost ~]$ su -
[root@localhost ~]# cd /usr/local/src
#安装依赖环境
[root@localhost src]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
#下载pcre包、解压、编译安装
[root@localhost src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@localhost src]# tar -zxvf pcre-8.35.tar.gz
[root@localhost src]# cd pcre-8.35
[root@localhost pcre-8.35]# ./configure
[root@localhost pcre-8.35]# make && make install
[root@localhost pcre-8.35]# cd ../
#下载nginx-1.6.2安装包、解压并安装
[root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[root@localhost src]# tar zxvf nginx-1.6.2.tar.gz
[root@localhost src]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@localhost nginx-1.6.2]# make && make install
[root@localhost nginx-1.6.2]# vim /usr/local/nginx/conf/nginx.conf
- 2 #user nobody;
+ 2 user www www;
#创建 www 用户和用户组, 不创建家目录
[root@localhost nginx-1.6.2]# useradd -M www
#配置开机启动服务
[root@localhost nginx-1.6.2]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx serve
After=network.service
StartLimitIntervalSec=0
[Service]
Type=forking
Restart=always
RestartSec=1
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
[root@localhost nginx-1.6.2]# systemctl enable nginx.service #开机启动
[root@localhost nginx-1.6.2]# systemctl start nginx #系统命令启动Nginx
#配置防火墙
[root@localhost nginx-1.6.2]# firewall-cmd --zone=public --add-port=80/tcp --permanent #开启80/tcp端口
[root@localhost nginx-1.6.2]# firewall-cmd --zone=public --add-port=443/tcp --permanent
[root@localhost nginx-1.6.2]# firewall-cmd --reload #重新载入配置
#基础命令操作
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx -v # 查看 Nginx版本
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx # 启动 Nginx
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx -s reopen # 重启 Nginx
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx -s stop # 停止 Nginx
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件(不会停止Nginx服务)