Linux CentOS 7 安装nginx 及 nginx配置
Linux CentOS 7 安装 nginx
linux版本:CentOS7 64位
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
下载“nginx-1.9.9.tar.gz”,移动到/usr/local/下。
wget https://nginx.org/download/nginx-1.9.9.tar.gz
nginx下载地址:https://nginx.org/download/
## 解压
tar -zxvf nginx-1.9.9.tar.gz
##进入nginx目录
cd nginx-1.9.9
## 配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 执行make、make install命令
make
make install
测试是否安装成功
# cd到刚才配置的安装目录
cd /usr/local/nginx/
./sbin/nginx -t
正常情况的信息输出:
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: [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
cd /usr/local/nginx/sbin
# 启动nginx
./nginx
在浏览器中输入服务器的ip地址,如:192.168.2.22
如果很不幸打不开链接,有可能是服务器的80端口被防火墙拦住了。
# CentOS7 查看防火墙是否开放80端口:
firewall-cmd --query-port=80/tcp
如果80端口没有开启,就开启80端口:
firewall-cmd --add-port=80/tcp --permanent
#--permanent 表示永久生效,没有此参数重启后失效
#重启防火墙
systemctl restart firewalld
刷新浏览器再次查看,可以看到nginx 欢迎页面表示成功。
配置完毕!
2、配置nginx开机自启动
vim /etc/rc.d/rc.local
# 新增一行:
/usr/local/nginx/sbin/nginx
软连接配置: 可以在任何位置执行 nginx 命令
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
重启nginx:
nginx -s reload
A little hug, little gift.
All of little something.
these are our meories.