对linux和前端感兴趣的人,都会把自己的项目放到服务器上去玩,希望所有的人都可以访问到,但是,也会有存在访问路径报403或404的错误,那怎么解决呢?其实是对路径访问出错。本期对这个问题来进行说明:
测试环境:虚拟机 VM ware
系统版本:RedHat 7.2 企业版
测试文件目录1:qm,index.html在【注意index.html的位置】
测试文件目录2:wsq_homepage【注意index.html的位置】
测试文件1:test.html
将这三个测试的文件,都存放在如下所示的目录:(由于博客是后期写的,所以qm文件已被,不影响操作,假设存在于/var/www/html)
在浏览器中访问需要通过命令安装一些服务(yum - y httpd,yum是需要先配置好的)
并关闭selinux:(为permissive表示关闭)
[root@localhost ~]# cd /etc/selinux/
[root@localhost selinux]# ls
[root@localhost selinux]# getenforce
Enforcing
[root@localhost selinux]# setenforce 0
[root@localhost selinux]# getenforce
Permissive
将80端口添加到防火墙规则:
[root@localhost selinux]# sudo firewall-cmd --query-port=80/tcp
no
[root@localhost selinux]# sudo firewall-cmd --permanent --zone=public --add-port=80/tcp\
> ^C
[root@localhost selinux]# sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@localhost selinux]# sudo firewall-cmd --permanent --zone=public --add-port=80/udp
success
[root@localhost selinux]# sudo firewall-cmd --reload
success
[root@localhost selinux]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2022-10-21 20:38:25 CST; 10min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 13862 (httpd)
Status: "Total requests: 6; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─13862 /usr/sbin/httpd -DFOREGROUND
├─13863 /usr/sbin/httpd -DFOREGROUND
├─13864 /usr/sbin/httpd -DFOREGROUND
├─13865 /usr/sbin/httpd -DFOREGROUND
├─13866 /usr/sbin/httpd -DFOREGROUND
├─13867 /usr/sbin/httpd -DFOREGROUND
└─14074 /usr/sbin/httpd -DFOREGROUND
10月 21 20:38:25 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
10月 21 20:38:25 localhost.localdomain httpd[13862]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set ...his message
10月 21 20:38:25 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
写index.html:
[root@localhost html]# vi index.html
this is test paga
这时,在redhat自带的火狐浏览器里,访问的地址为:127.0.0.1/index
如何将自己写的静态网页上传到虚拟机呢?可以用Xshell、SecureCRT等软件,将上面所说的两个网页目录,上传到html下,访问路径:
http://127.0.0.1/test/html/index.html
访问地址:http://127.0.0.1/wsq_homepage/index.html
也就是说,在浏览器中访问的是 主机地址+网页文件夹下的index.html ---->127.0.0.1+test(网页的主目录+直到index.html)。那为什么是这样,为什么不加前面的端口的?为什么又不加var/www/,因为httpd启动工作路径在var/www/目录下!
腾讯云服务器免费上传静态页面教程: