美文网首页
小白学nginx之搭建一个静态资源web服务器

小白学nginx之搭建一个静态资源web服务器

作者: 乔治大叔 | 来源:发表于2020-04-07 16:12 被阅读0次

编写Nginx配置文件

[root@web01 conf.d]# cat game.conf
server {
    listen 80;
    server_name game.oldboy.com;

    location / {
        root /code;
        index index.html;
    }
}

根据配置文件,创建目录,上传代码

[root@web01 ~]# mkdir /code
[root@web01 ~]# cd /code
[root@web01 ~]# rz html5.zip
[root@web01 code]# unzip html5.zip 

重载nginx服务

[root@web01 code]# systemctl restart nginx      #立即重启
[root@web01 code]# systemctl reload nginx       #平滑重启

配置域名解析

Windows:  C:\Windows\System32\drivers\etc
                10.0.0.7      www.test.com
                
Mac   sudo vim /etc/hosts
                10.0.0.7      www.test.com
            
C:\Users\Administrator>ping www.test.com        #检查解析的是否是10.0.0.7
正在 Ping www.test.com [10.0.0.7] 具有 32 字节的数据:
来自 10.0.0.7 的回复: 字节=32 时间=9ms TTL=64
来自 10.0.0.7 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.7 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.7 的回复: 字节=32 时间<1ms TTL=64

通过浏览器访问对应的项目

http://www.test.com/game/duxinshu/index.html    用户请求的路径

实际上服务器查找的路径     /code/game/duxinshu/index.html

相关文章

网友评论

      本文标题:小白学nginx之搭建一个静态资源web服务器

      本文链接:https://www.haomeiwen.com/subject/wbdubctx.html