第一步:安装nginx官网yum源
[root@web01 ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
第二步:安装nginx
[root@web01 ~]# yum install nginx -y
第三步:启动、开机自启
[root@web01 ~]# systemctl start nginx [root@web01 ~]# systemctl enable nginx
第四步:修改配置文件
[root@web01 ~]# vim /etc/nginx/conf.d/www.conf
server {
listen 0.0.0.0:80; #监听端口
server_name www.blog.com; #网站地址
location /{
root /var/www/html/; #网站目录
index index.php index.html; #网站首页
}
location ~ .php$ { #添加 PHP 服务(前提已装PHP)
root /var/www/html/; #网站目录
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
第五步:创建网站测试文件
[root@web01 ~]# echo "hello,this is index.html" >/var/www/html/index.txt [root@web01 ~]# echo "" >/var/www/html/index.php
第六步:测试配置文件,重启nginx服务
[root@web01 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@web01 ~]# systemctl restart nginx
ps:查看nginx服务 + 端口号
[root@web01 ~]# ps -ef|grep "nignx" root 3280 1 0 17:39 ? 00:00:00 nginx: master process /usr/sbin/nginx www 3281 3280 0 17:39 ? 00:00:00 nginx: worker process www 3282 3280 0 17:39 ? 00:00:00 nginx: worker process root 3288 1697 0 17:46 pts/0 00:00:00 grep --color=auto nginx [root@web01 ~]# netstat -lnp|grep "80" tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3280/nginx: master tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3280/nginx: master tcp6 0 0 :::80 :::* LISTEN 3280/nginx: master
第七步:打开浏览器测试
ps:关闭 防火墙 + selinux
[root@web01 ~]# systemctl stop firewalld [root@web01 ~]# systemctl disable firewalld [root@web01 ~]# setenforce 0 [root@web01 ~]# sed -i 's#enforcing#disable#g' /etc/selinux/config



