Nginx 安装部署

Nginx安装部署

1 版本区别

常用版本分为四大阵营

  • Nginx开源版:http://nginx.org/
  • Nginx plus 商业版:https://www.nginx.com
  • Openresty:http://openresty.org/cn/
  • Tengine:http://tengine.taobao.org/

2 编译安装

./configure --prefix=/usr/local/nginx

make

make install

如果出现警告或报错

提示:

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
安装gcc:yum install -y gcc

提示:

./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.
安装perl库:yum install -y pcre pcre-devel

提示:

./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.
安装zlib库:yum install -y zlib zlib-devel

3 启动Nginx

进入安装好的目录 /usr/local/nginx/sbin

./nginx 启动

./nginx -s stop 快速停止

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

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

4 关于防火墙

关闭防火墙

systemctl stop firewalld.service

禁止防火墙开机启动

systemctl disable firewalld.service

放行端口

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

重启防火墙

firewall-cmd --reload

5 安装成系统服务

创建服务脚本

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-reload

启动服务

systemctl start nginx.service

开机启动

systemctl enable nginx.service

安装部署Windows版Nginx的步骤如下: 1. 首先,从官方网站下载Nginx安装包。可以在官网上找到文档和下载链接,如右侧的"documentation -> nginx windows"。 2. 下载完成后,解压安装包。 3. 打开命令提示符(cmd),进入解压后的Nginx目录。 4. 使用命令启动Nginx,请注意不要直接双击nginx.exe。直接双击会导致修改配置后重启、停止Nginx无效,需要手动关闭任务管理器内的所有Nginx进程,再启动才能生效。 5. 在浏览器中输入localhost或指定的IP地址,确认Nginx是否成功安装并运行。 请注意,以上步骤仅适用于Windows版Nginx 1.22.0。安装后,你可以根据需要进一步配置Nginx,如修改配置文件、添加网站等。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Nginx Windows详细安装部署教程](https://blog.csdn.net/weixin_43960684/article/details/103401921)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Nginx 1.22.0 Windows版本,解压安装。](https://download.csdn.net/download/u011966169/85640409)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值