Linux下nginx安装教程
一、准备工作
Nginx安装版本:nginx-1.8.1.tar.gz
Linux环境:
二、安装nginx
1、把nginx-1.8.1.tar.gz放到/usr/locad/下
2、解压安装包:tar -xvf nginx-1.8.1.tar.gz
3、修改安装包名称:mv nginx-1.8.1 nginx
4、进入nginx目录:cd nginx
5、配置./configure
6、编译安装make && make install
三、验证是否成功启动
1、在/usr/local/nginx/sbin目录执行./nginx -r reload启动nginx
2、在浏览器中输入http://ip:80出现如下界面,表示启动成功
四、安装过程遇见问题
1、问题1,执行./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=<path> option.
解决办法:
执行:yum -y install pcre-devel命令即可
2、问题2,./nginx -s reload重启时报错
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
解决方法:
提示没有这个文件,是因为在nginx目录下没有logs文件夹,创建一个在启动即可
cd /usr/local/nginx
mkdir logs
cd sbin
./nginx -s reload
3、问题3,目录为同一级
make[1]: Leaving directory `/usr/local/nginx'
make -f objs/Makefile install
make[1]: Entering directory `/usr/local/nginx'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' || mv '/usr/local/nginx/sbin/nginx' '/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp: "conf/koi-win" 与"/usr/local/nginx/conf/koi-win" 为同一文件
make[1]: *** [install] 错误 1
make[1]: Leaving directory `/usr/local/nginx'
make: *** [install] 错误 2
这是因为编译安装过一次,再次编译安装是,sbin等文件夹已经存在所以会包这个错误,可以删除该文件夹再次安装,或者忽略该错误
4、问题4,解决 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
使用/usr/local/nginx/sbin/nginx -s reload 重新读取配置文件出错
[root@localhost nginx]/usr/local/nginx/sbin/nginx -s reload
提示 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost nginx]# cd logs
[root@localhost logs]# ls
access.log error.log nginx-access.log nginx_error.log
果然没有/usr/local/nginx/logs/nginx.pid 文件
解决方法:用指定文件加载nginx配置文件
[root@localhost nginx]/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
2020-01-04 (五十四)自动化测试高级应用之Page Object设计模式-认识Page Object
2020-01-04 (五十三)自动化测试高级应用之自动发邮件功能-整合自动发邮件功能