在linux下安装nginx,首先需要安装 gcc-c++编译器。然后安装nginx依赖的pcre和zlib包。最后安装nginx即可
yum install gcc-c++
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
tar -zxvf nginx-1.23.2.tar.gz
mv nginx-1.23.2 nginx
cd nginx
./configure
make && make install
whereis nginx
cd sbin
./nginx
错误如下
1、分析原因
nginx/目录下没有logs文件夹
2、解决方案 :创建文件夹并授权
mkdir logs
chmod 700 logs
3、验证
输入以下命令
/usr/local/nginx/sbin/nginx -t
4、正常情况的信息输出:
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正常启动:
systemctl status firewalld
手动开启端口命令
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义: --zone #作用域 --add-port=80/tcp #添加端口,格式为:端口/通讯协议 --permanent #永久生效,没有此参数重启后失效
systemctl restart firewalld.service
firewall-cmd --list-all
netstat -tunlp | grep 80
这里因为我之前开启了的是被nginx.master或者nginx.woeker占用就不用管,如果不是这个的话那就把那个进程关闭掉
kill -9 进程号
关闭之后重启nginx再次访问!!