centos7 安装nginx

1.解压

tar -xf nginx-1.10.1.tar.gz

2.配置

cd nginx-1.10.1

./configure --prefix=/data/my/nginx(注意这个目录是一个新目录,不是解压的源文件目录)

此时可能会提示

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel与openssl-devel解决问题
yum -y install pcre-devel openssl openssl-devel
 
./configure: error: C compiler cc is not found
yum -y install gcc gcc-c++ autoconf automake make
 
./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
 
./configure: error: the HTTP gzip module requires the zlib library.
 yum install -y zlib-devel
 
 
然后继续
./configure --prefix=/data/my/nginx --with-http_ssl_module#如果不用https可以省掉后面这个参数
make
make install
 
安装完成后
cd /data/my/nginx/sbin
运行ng
./nginx
 
查看ng进程
ps -ef|grep nginx
查看80端口是否被ng占用lsof -i tcp:80
启动,停止,重载ng
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload

重启ng,先停止再启动(推荐)
./nginx -s quit
./nginx
 
在浏览器上试着访问http://ip:80,如不能访问,可能是防火墙的问题
firewall-cmd --state#查看防火墙状态<br />systemctl start firewalld.service#启动firewall<br />systemctl stop firewalld.service#停止firewall<br />systemctl disable firewalld.service#禁止firewall开机启动<br />
 
如果开启了防火墙,要执行以下命令:
firewall-cmd --permanent --add-service=http<br />firewall-cmd --permanent --zone=trusted --add-port=80/tcp
 

 开机启动

vi /lib/systemd/system/nginx.service
复制:
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
 
保存完毕后
systemctl enable nginx.service
 

相关推荐