Centos7部署nginx的虚拟目录

一、系统环境:
Centos7.6系统最小化安装

二、最小化安装Linux之后需要安装开发者工具

yum -y groupinstall "Development Tools"

如果记不住工具包的名称,可以使用下面命令搜索

[root@localhost ~]# yum grouplist | more
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.bfsu.edu.cn
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

三、准备安装
1.1、下载rpm包

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

1.2、安装nginx的源码包

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

1.3、开始安装nginx

yum -y install nginx

1.4、启动nginx

systemctl start nginx
systemctl enable nginx

1.5、开启防火墙允许访问并关闭selinux
1.5.1、防火墙放行nginx服务或者80端口

firewall-cmd --add-service=http --permanent //或者
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

1.5.2、关闭selinux

setenforce 0  ###临时关闭
永久关闭可以修改/etc/selinux/config,修改SELINUX=permissive或disabled
或者使用:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

1.6、开启虚拟目录
1.6.1、编辑nginx的主配置文件default.cog

vi /etc/nginx/conf.d/default.conf

插入内容:

location /1 {
        root            /usr/share/nginx/html;
        index index.php index.html index.htm;
    }
###访问http://localhost/1,即可访问到/usr/share/nginx/html/1/index.html文件

1.7、测试

访问:http://localhost/1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值