侧边栏壁纸
  • 累计撰写 89 篇文章
  • 累计创建 17 个标签
  • 累计收到 23 条评论

目 录CONTENT

文章目录

linux 下安装 nginx

Administrator
2023-12-27 / 0 评论 / 0 点赞 / 39 阅读 / 0 字

linux 版本:CentOS7 64 位

【yum 安装最新版 nginx:https://www.cnblogs.com/xxoome/p/7256214.html】

在安装 nginx 前首先要确认系统中安装了 gcc、pcre-devel、zlib-devel、openssl-devel

Linux 下检查是否安装过某软件包:http://www.cnblogs.com/xxoome/p/5866553.html

安装命令:

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

nginx 下载地址:https://nginx.org/download/

下载“nginx-1.9.9.tar.gz”,移动到 /usr/local/ 下。

复制代码

复制代码

## 解压
tar -zxvf nginx-1.9.9.tar.gz

##进入nginx目录
cd nginx-1.9.9
## 配置
./configure --prefix=/usr/local/nginx

# make
make
make install

复制代码

复制代码

make 报错:error: this statement may fall through [-Werror=implicit-fallthrough=]

继续执行make操作,报出error: this statement may fall through [-Werror=implicit-fallthrough=]

问题处理

原因:表示打开gcc的所有警告 -Werror,它要求gcc将所有的警告当成错误进行处理

将 -Werror 直接去掉再重新make

其中:

-Wall 表示打开gcc的所有警告

-Werror,它要求gcc将所有的警告当成错误进行处理

打开:vim objs/Makefile 去掉-Werror即可

make报错:error: ‘struct crypt_data’ has no member named ‘current_salt’

继续执行make,报出error: ‘struct crypt_data’ has no member named ‘current_salt’

问题处理

原因:定义的crypt_data结构体中没有current_salt这个成员
处理:将有问题的那一行注释掉
进入到 src/os/unix/ngx_user.c中,注释掉第38行

OK,现在可以执行 make 了。

执行 make、make install 命令

测试是否安装成功

# cd到刚才配置的安装目录/usr/loca/nginx/
./sbin/nginx -t

错误信息

nginx: [alert] could not open error log file: open()"/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2016/09/13 19:08:56 [emerg] 6996#0: open()"/usr/local/nginx/logs/access.log" failed (2: No such file or directory)

原因分析:nginx/ 目录下没有 logs 文件夹

解决方法

mkdir logs
chmod 700 logs

正常情况的信息输出:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动 nginx

cd /usr/local/nginx/sbin
./nginx //启动nginx

在浏览器中输入服务器的 ip 地址,如:192.168.1.12

很不幸,打不开链接。下面进行原因排查:

说明服务器的 80 端口是打不开的。

因为我使用的 linux 系统版本是 CentOS7,所以可以在服务器中执行如下命令来验证》》

firewall-cmd --query-port=80/tcp


显然 80 端口没有开启。

下面我们开启 80 端口:

firewall-cmd --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld

--permanent #永久生效,没有此参数重启后失效

刷新浏览器


====================== 分割线 ====================

配置完毕!

2、配置 nginx 开机自启动

vim /etc/rc.d/rc.local

0

评论区