安装nginx
前提:在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
若无:
安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
1. 下载nginx.
Nginx下载地址:
http://nginx.org/download/
下载“nginx-1.9.8.tar.gz”,移动到/usr/local/下.
2. 解压,并安装.
解压
tar -zxvf nginx-1.9.8.tar.gz
##进入nginx目录
cd nginx-1.9.8
配置
./configure –prefix=/usr/local/nginx
#make
make
make install
3. 测试安装
跳转到刚才配置的安装目录/usr/local/nginx/
cd /usr/local/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
CentOS7的版本linux系统下:
验证80端口是否开启命令:
firewall-cmd –query-port=80/tcp
若为no,则打开80端口,命令如下
( –permanent #永久生效,没有此参数重启后失效):
firewall-cmd –add-port=80/tcp –permanent
#重启防火墙
systemctl restart firewalld
再次访问浏览器:
成功.
5.配置nginx开机启动
vim /etc/rc.d/rc.local
rc.local其中添加
#开机启动nginx
/usr/local/nginx/sbin/nginx