CentOS7安装nginx

Linux安装wget命令:

yum -y install wget

安装依赖

yum install -y gcc
yum install -y pcre pcre-devel 
yum install -y zlib zlib-devel 
yum install -y openssl openssl-dev

安装nginx详细步骤:

cd /usr/local
mkdir nginx
cd nginx

下载nginx:

wget http://nginx.org/download/nginx-1.2.4.tar.gz

解压:

tar -xvf  nginx-1.2.4.tar.gz

--安装:

cd /usr/local/nginx
cd nginx-1.2.4

//执行命令:

./configure

//执行make命令:

make

//执行make install 命令:

make install

--配置:

vi /usr/local/nginx/conf/nginx.conf

改端口:80->8089(因为80端口可能被apache占用)

--启动Nginx

/usr/local/nginx/sbin/nginx -s reload

如果报错:nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed

则运行:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

再次启动

查看nginx进程是否启动:

ps -ef | grep nginx

若想使用外部主机连接上虚拟机访问端口192.168.*.,需要关闭虚拟机的防火墙:

centOS6及以前版本使用命令:

 systemctl stop iptables.service

centos7:

systemctl stop firewalld.service

如果浏览器访问虚拟机ip不成功,则是防火墙的问题,进行如下操作:

开启Nginx默认8089(默认80)端口,未开启无法访问Nginx

firewall-cmd --zone=public --add-port=8089/tcp --permanent

关闭防火墙:

systemctl stop firewalld.service

启动防火墙:

systemctl start firewalld.service

查看防火墙运行状态:

systemctl status Firewalld.service

然后浏览器带输入ip+端口 访问成功!

----安装完成一般常用命令

进入安装目录中:

 cd /usr/local/nginx/sbin

启动,关闭,重启,命令:

./nginx  (启动)

./nginx -s stop (关闭)

./nginx -s reload (重启)

你可能感兴趣的:(CentOS7安装nginx)