0
点赞
收藏
分享

微信扫一扫

0.Nginx 安装使用和配置


Nginx 安装

下载

常用版本分为四大阵营

  1. Nginx开源版
    ​​http://nginx.org/​​
  2. Nginx plus 商业版
    ​​https://www.nginx.com​​
  3. openresty
    ​​http://openresty.org/cn/​​
  4. Tengine
    ​​http://tengine.taobao.org/​​

使用开源版本的即可.

进行下载:
​​​https://nginx.org/en/download.html​​

0.Nginx 安装使用和配置_Nginx

安装配置

提前安装依赖

yum install -y gcc

yum install -y pcre pcre-devel

yum install -y zlib zlib-devel

编译和安装

将 安装包进行上传到服务器,然后进行解压

// 解压
tar -zvf nginx-1.23.2.tar.gz
// 重命名
mv nginx-1.23.2 nginx

// 进入目录下
cd nginx

进行编译和安装

// 安装在  /usr/local/nginx 目录下
./configure --prefix=/usr/local/nginx
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module

// 安装
make && make install

启动

进入到 /usr/local/nginx 目录下, sbin 目录

cd /usr/local/nginx/sbin

// 启动 
./nginx

// 快速停止
./nginx -s stop

// 优雅关闭,在退出前完成已经接受的连接请求
./nginx -s quit

// 重新加载配置
./nginx -s reload

如果是 windows 版本的 nginx

0.Nginx 安装使用和配置_服务器_02

启动: 双击 nginx.exe

重新加载: cmd 窗口下 当前目录,

nginx.exe -s reload

C:\Users\20481\Downloads\nginx-1.22.1>nginx.exe -s reload

关闭: cmd 窗口下,当前目录:

nginx.exe -s stop

C:\Users\20481\Downloads\nginx-1.22.1>nginx.exe -s stop

防火墙配置

// 关闭防火墙 

systemctl stop firewalld.service

// 禁止防火墙开机启动

systemctl disable firewalld.service

// 放行端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

// 重启防火墙

firewall-cmd --reload

将 nginx 注册成服务

创建服务脚本

vim /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 /etc/nginx/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-reload

// 启动服务
systemctl start nginx.service

// 开机启动

systemctl enable nginx.service

// 后续更新配置文件之后
systemctl reload nginx.service


举报

相关推荐

0 条评论