栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

centos7

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

centos7

第一步:安装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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/882133.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号