Linux中使用curl命令出现403错误的解决办法(亲测有效)

Linux中使用curl命令出现403错误的解决办法

403错误,是网站访问过程中,常见的错误提示,资源不可用

服务器理解客户请求,但拒绝处理它,通常由于服务器上文件或目录的权限设置导致,

比如IIS或者apache设置访问权限不当。

一般回出现以下错误提示:403错误!,关闭了IE的显示友好的http错误,

显示没有权限访问(You don’t have permission to access / on this server)!

 

如果是linux

做实验时,访问该主机IP,发现是apache主页(这是),不能访问里面的内容

[root@foundation21 kiosk]# curl -I www.westos.org

HTTP/1.1 403 Forbidden

Date: Thu, 20 Feb 2020 04:14:58 GMT

Server: Apache/2.4.6 (Red Hat Enterprise Linux)

Last-Modified: Wed, 03 Aug 2016 12:24:48 GMT

ETag: "f91-53929eb51c400"

Accept-Ranges: bytes

Content-Length: 3985

Content-Type: text/html; charset=UTF-8

 

在linux中这个一般是权限问题,即被火墙当在外面

查看服务端的selinux和firewalld的状态

[root@server3 ~]# getenforce

Enforcing

[root@server3 ~]# setenforce 0

[root@server3 ~]# getenforce

Permissive

 

我们临时改变selinux的状态

[root@server3 ~]# getenforce

Enforcing

[root@server3 ~]# setenforce 0

[root@server3 ~]# getenforce

Permissive

然后我们在用真机访问服务端时就可以了  200状态码表示访问成功

[root@foundation21 kiosk]# curl -I www.westos.org

HTTP/1.1 200 OK

Date: Thu, 20 Feb 2020 04:27:54 GMT

Server: Apache/2.4.6 (Red Hat Enterprise Linux)

Last-Modified: Thu, 20 Feb 2020 03:16:20 GMT

ETag: "17-59ef954339bf8"

Accept-Ranges: bytes

Content-Length: 23

Content-Type: text/html; charset=UTF-8

 

发布了150 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43309149/article/details/104496434
今日推荐