Nginx安装
Linux
tar -zxvf xxx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
## 配置编译路径
make
make install
报错提示
- 安装gcc
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
安装命令
yum install -y gcc
- 安装perl库
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
安装命令
yum install -y pcre pcre-devel
- 安装zlib库
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
安装命令
yum install -y zlib zlib-devel
启动Nginx
./nginx ## 启动
./nginx -s stop ## 快速停止
./nginx -s quit ## 优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload ## 重新加载配置
注册至服务
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
服务命令
## 重新加载系统服务
systemctl daemon-load
## 启动服务
systemctl start nginx
## 开机启动
systemctl enable nginx
防火墙策略
## 指定端口和ip访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.123.100" port protocol="tcp" port="8080" accept"
## 移除规则
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.123.100" port port="8080" protocol="tcp" accept"
## 关闭防火墙
systemctl stop firewalld
systemctl start firewalld
## 重载防火墙规则
firewall-cmd --reload
## 查看已配置规则
firewall-cmd --list-all