nginx安装部署

本文详细介绍了如何手动安装nginx 1.18.0,包括下载安装包、解压、编译以及安装依赖库pcre、openssl和zlib。在编译过程中可能遇到的问题,如缺少依赖、配置错误等,也提供了解决方案,例如安装gcc-c++环境和修改端口绑定。最后,通过curl检查nginx服务器是否正常运行。

nginx安装部署

1. 首先下载安装包(此次安装使用的是1.18版本)

nginx-1.18.0.tar.gz

2. 解压缩nginx

tar -zxvf nginx-1.18.0.tar.gz

3. 进入nginx-1.18目录进行编译

cd nginx-1.18
./configure
此时报错:./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= option.
(需要安装依赖的pcre、openssl、zlib库)

4. 安装pcre、openssl、zlib库(有yum的可以直接使用yum安装)

yum -y install pcre
yum -y install openssl
yum -y install zlib
(无法使用yum的情况,需要下载安装包)
pcre-8.44.tar.gz
tar zxvf pcre-8.44.tar.gz
tar zxvf openssl-1.1.1l.tar.gz
tar zxvf zlib-1.2.11.tar.gz

5. 编译nginx安装软件(制定安装目录和依赖包位置)

cd nginx-1.18
./configure --prefix=/nginx/nginx --with-openssl=/nginx/openssl-1.1.1l --with-pcre=/nginx/pcre-8.44 --with-zlib=/nginx/zlib-1.2.11
make && make install
*报错:configure: error: Invalid C++ compiler or C++ compiler flags
这是因为系统缺失 gcc-c++ 库,需要使用root安装gcc-c++环境:
yum -y install gcc-c++
yum install -y gcc
完成后再次执行make就可以了

6.启动nginx

cd /nginx/nginx/sbin
./nginx
报错:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
以非root权限启动时,会出现 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 错误,将 /usr/local/nginx/conf/nginx.conf 文件中的80端口改为1024以上(8080)

7. 测试nginx网页访问是否正常

curl http://ip:8080

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

### Linux系统安装部署Nginx 添加Nginx为系统服务: ```bash cd /lib/systemd/system/ vim nginx.service ``` 在`nginx.service`文件中添加以下内容: ```plaintext [Unit] Description=nginx service After=network.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 quit PrivateTmp=true [Install] WantedBy=multi-user.target ``` 执行以下命令使Nginx服务生效并启动: ```bash systemctl enable nginx && systemctl start nginx ``` 至此,Nginx安装完成并以系统服务形式启动[^1]。 ### Windows系统安装部署Nginx 下载完成后,解压(示例解压到D盘),运行cmd使用命令进行操作,不要直接双击`nginx.exe`,若不小心双击了,可在任务管理器找到nginx结束任务即可[^3]。 ### 验证安装部署 访问部署ip,若能看到特定界面则表示安装部署成功。同时,可使用以下命令进行Nginx的重启和关闭操作: ```bash # nginx 重启 ./nginx -s reload # nginx关闭,需先使用ps –ef|grep nginx查看主进程号(带master字样的进程号) ps –ef|grep nginx kill -QUIT 主进程号 ``` ### 修改配置 通常在`nginx.conf`文件中修改配置,修改后需重启Nginx使配置生效,默认端口是80,默认安装路径是`/data/nginx-1.16.1/html`,配置文件路径为`/data/nginx-1.16.1/conf`,重启命令如下: ```bash ./nginx -s reload ``` 以上为Nginx安装到基本配置的流程,若需更详细配置(如高可用集群、缓存优化),可参考Nginx官方文档或优快云相关专题[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值