安装nginx--服务器:CentOS 7.6
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
官网nginx下载地址:https://nginx.org/download/
下载“nginx-1.16.1.tar.gz”,移动到/usr/local/下。
wget -c https://nginx.org/download/nginx-1.16.1.tar.gz
解压安装
tar -zxvf nginx-1.16.1.tar.gz
进入nginx目录
cd nginx-1.16.1
//配置
./configure --prefix=/usr/local/nginx
//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
在命令行窗口测试一下80端口是否通
ping 端口号:80

连接失败
我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证》》
firewall-cmd --query-port=80/tcp

显然80端口没有开启。
下面我们开启80端口:
firewall-cmd --add-port=80/tcp --permanent
重启防火墙
systemctl restart firewalld
** --permanent #永久生效,没有此参数重启后失效**
打开浏览器输入ip回车

成功
开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行
/usr/local/nginx/sbin/nginx

浙公网安备 33010602011771号