尝试在浏览器中访问Apache 2.4.7 Web服务器时出现403错误

阿希尔

当我从同一台Web服务器PC使用本地主机访问Apache Web服务器时,它将显示Apache2 Ubuntu默认页面。

但是,当我使用192.168.0.2访问Apache Web服务器时,它显示403 Forbidden错误(Forbidden您无权访问此服务器上的/)。

Web服务器详细信息

  • Ubuntu 14.04 LTS
  • Apache版本2.4.7

所有权命令

www-data sudo adduser ftpuser www-data
sudo chown -R www-data:ftpuser /var/www
sudo chmod -R g+rwX /var/www

etc / apache2 / apache2.conf文件中

ServerName 192.168.0.2

<Directory/>
    AllowOverride All
    Require all granted
</Directory>

etc / apache2 / port.conf文件中

NameVirtualHost *:80
Listen *:80

一个网站的虚拟主机

<VirtualHost *:80>
    ServerName mysite
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Options None FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>    
</VirtualHost>

我需要在什么地方进行哪些设置?请帮忙...

pa4080

1.您应该这样配置/ etc / hosts文件

127.0.0.1   localhost
127.0.0.1   test-site
127.0.1.1   my-hostname
# The following lines are desirable for IPv6 capable hosts. etc...

test-site第二个“本地主机”在哪里并且my-hostname是中定义的“系统主机名” /etc/hostname


2.您应该定义并启用虚拟主机(VH):

有一个默认的HTTP VH。它放在中/etc/apache2/sites-available/档案名称为000-default.conf您必须对其进行编辑(如果需要,可以对其进行重命名,或者基于该文件创建其他一些.conf文件),然后必须启用它。

您可以通过创建“软符号链接”来手动启用它:

sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/

或者,您可以使用称为a2ensite的Apache2工具,该工具具有相同的功能:

sudo a2ensite 000-default.conf

假设有3个虚拟主机,启用的SSL和注册的私有域(例如SOS.info):

/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf

出于本主题的目的而创建的一个:

/etc/apache2/sites-available/http.test-site.conf

前两个VH的内容是:

$ cat /etc/apache2/sites-available/http.SOS.info.conf

<VirtualHost *:80>    
    ServerName SOS.info
    ServerAlias www.SOS.info
    ServerAdmin [email protected]

    # Redirect Requests to SSL
    Redirect permanent "/" "https://SOS.info/"

    ErrorLog ${APACHE_LOG_DIR}/http.SOS.info.error.log
    CustomLog ${APACHE_LOG_DIR}/http.SOS.info.access.log combined       
</VirtualHost>

这将所有HTTP请求重定向到HTTPS。

$ cat /etc/apache2/sites-available/https.SOS.info.conf

<IfModule mod_ssl.c>    
    <VirtualHost _default_:443>    
        ServerName SOS.info
        ServerAlias www.SOS.info
        ServerAdmin [email protected]

        DocumentRoot /var/www/html  

        SSLEngine on    
        SSLCertificateFile /etc/ssl/certs/SOS.info.crt
        SSLCertificateKeyFile /etc/ssl/private/SOS.info.key
        SSLCertificateChainFile /etc/ssl/certs/SOS.info.root-bundle.crt
        #etc..
    </VirtualHost>    
</IfModule>

这是HTTPS VH。

这两个文件的内容可以发布到一个文件中,但是在这种情况下,它们的管理(a2ensite/ a2dissite)将更加困难。


第三个虚拟主机就是为了我们的目的而创建的

$ cat /etc/apache2/sites-available/http.test-site.conf

<VirtualHost *:80>
    ServerName test-site
    ServerAlias test-site.SOS.info

    DocumentRoot /var/www/test-site
    DirectoryIndex index.html

    ErrorLog ${APACHE_LOG_DIR}/test-site.error.log
    CustomLog ${APACHE_LOG_DIR}/test-site.access.log combined

    <Directory /var/www/test-site>
        # Allow .htaccess 
        AllowOverride All
        Allow from All
    </Directory>    
</VirtualHost>

3.使用此配置,您应该访问:

http://localhost     # pointed to the directory of the mine Domain 
https://localhost    # iin our case: /var/www/html (SOS.info), but you should get an error, because the SSL certificate

http://SOS.info      # which redirects to https://SOS.info
https://SOS.info     # you should have valid SSL certificate

http://www.SOS.info  # which is allied to http://SOS.info and redirects to https://SOS.info
https://www.SOS.info # which is allied to https://SOS.info

在主要示例中,您应该访问和

http://test-site           # pointed to the directory /var/www/test-site
http://test-site.SOS.info  # which is allied to http://test-site

尝试在Web浏览器中打开网站,或尝试(在终端中)使用以下命令:

$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html

当然,您需要index.html在其DocumentRoot中包含一些页面:)



由于脚手架的原因,我将留下下一个音符:)


4.您需要正确配置`/ etc / apache2 / apache2.conf`。

最好花一些时间来提高服务器的安全性。这些手册是关于安全性配置的:1st2nd您可以在这里获得免费的SSL证书。这些站点将帮助您检查进度:1st2nd

根据以上安全手册/etc/apache2/apache2.conf文件必须如下所示:

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 60

#KeepAlive Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options None FollowSymLinks 
    AllowOverride None
    Require all denied
</Directory>

<Directory /var/www/>
    Options None FollowSymLinks 
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

# Hide Server type in the http error-pages 
ServerSignature Off
ServerTokens Prod

# Etag allows remote attackers to obtain sensitive information 
FileETag None

# Disable Trace HTTP Request
TraceEnable off

# Set cookie with HttpOnly and Secure flag.
# a2enmod headers
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

# Clickjacking Attack
Header always append X-Frame-Options SAMEORIGIN

# CX-XSS Protection
Header set X-XSS-Protection "1; mode=block"

# Disable HTTP 1.0 Protocol
RewriteEngine On
RewriteCond %{THE_REQUEST} !HTTP/1.1$
RewriteRule .* - [F]

# Change the server banner @ ModSecurity 
# Send full server signature so ModSecurity can alter it
ServerTokens Full
# Alter the web server signature sent by Apache
<IfModule security2_module>
    SecServerSignature "Apache 1.3.26"
</IfModule>
Header set Server "Apache 1.3.26"
Header unset X-Powered-By

# Hde TCP Timestamp
#   gksu gedit /etc/sysctl.conf
#   >> net.ipv4.tcp_timestamps = 0
# Test: sudo hping3 SOS.info -p 443 -S --tcp-timestamp -c 1

# Disable -SSLv2 -SSLv3 and weak Ciphers
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"

5.设置防火墙。

要允许/拒绝外部访问Web服务器,可以使用UFW(非复杂防火墙):

sudo ufw allow http
sudo ufw allow https

要仅允许使用tcp协议:

sudo ufw allow http/tcp
sudo ufw allow https/tcp

您可以直接使用和端口号:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

以防万一您可以重新加载“规则表”:

sudo ufw reload

您可以使用UFW的GUI界面,称为gufw

sudo apt update
sudo apt install gufw
gufw &

选择Office配置文件。它将为:Status:ONIncoming:DenyOutgoing:Allow添加你的规则。


6.如果您有路由器,请不要忘记转发一些端口:

如果您有路由器,并且希望可以从Internet访问Web服务器,请不要忘记添加一些端口转发。这样的东西

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试在浏览器中访问Apache 2.4.7 Web服务器时出现403错误

来自分类Dev

尝试通过 Angular 8 访问时出现身份服务器 4 CORS 错误

来自分类Dev

从主机Web浏览器访问Docker容器中驻留的apache2

来自分类Dev

Apache2服务器上的403禁止错误

来自分类Dev

EC2实例无法在浏览器中访问

来自分类Dev

带有Rails4的浏览器无法访问ec2实例

来自分类Dev

访问apache2中的php页面时发生内部服务器错误

来自分类Dev

访问apache2中的php页面时发生内部服务器错误

来自分类Dev

无法通过在centos 7上配置的浏览器访问vsftp服务器

来自分类Dev

在Windows上用PHP模块启动Apache时出错:“无法将php5apache2_4.dll加载到服务器中:访问被拒绝”

来自分类Dev

在Win 7 OS的Safari浏览器中,Bootstrap 2组件已损坏

来自分类Dev

使用 api 密钥使用 Web API 时,出现以下错误 - 远程服务器返回错误:(403) Forbidden

来自分类Dev

无法在Windows 7中启动服务器服务。错误2:找不到文件

来自分类Dev

访问远程服务器IIS7上的虚拟目录时出现运行时错误

来自分类Dev

部署(iis7,asp.net mvc4)时,如何使Visual Studio解决方案中的文件夹出现在服务器上?

来自分类Dev

无法在 Raspberry Pi 上挂载 Synology 服务器,但可以在文件浏览器中访问它(挂载错误(2):没有这样的文件或目录)

来自分类Dev

引导时出现“ psycopg2.OperationalError:无法连接到服务器:连接被拒绝”错误

来自分类Dev

引导时出现“ psycopg2.OperationalError:无法连接到服务器:连接被拒绝”错误

来自分类Dev

在IIS中部署.NET Core RC2时出现服务器错误502

来自分类Dev

调用服务器到服务器CloudKit Web服务时出现授权错误

来自分类Dev

尝试对客户端服务器ssl进行身份验证时,Tomcat 7获取SSLv2Hello被禁用错误

来自分类Dev

获取“检测到GTK + 2.x符号”。尝试使用CommandBox启动服务器时出现错误

来自分类Dev

尝试使用 eclipse juno 服务器运行 struts2 时,出现 HTTP 状态 404 错误

来自分类Dev

从远程服务器提交neo4j批处理时出现IncompleteRead错误;格式错误的HTTP响应

来自分类Dev

从远程服务器提交neo4j批处理时出现IncompleteRead错误;格式错误的HTTP响应

来自分类Dev

将SSL请求从Apache服务器转发到Tomcat时出现403(禁止)错误

来自分类Dev

Install4j:在 CentOS 7 服务器中执行安装程序无法启动并出现异常

来自分类Dev

通过AJAX POST请求将大型文件传递到服务器时发生错误(IIS 7,ASP.NET MVC 4)

来自分类Dev

创建Gradle项目时出现错误:服务器返回了HTTP响应代码:403

Related 相关文章

  1. 1

    尝试在浏览器中访问Apache 2.4.7 Web服务器时出现403错误

  2. 2

    尝试通过 Angular 8 访问时出现身份服务器 4 CORS 错误

  3. 3

    从主机Web浏览器访问Docker容器中驻留的apache2

  4. 4

    Apache2服务器上的403禁止错误

  5. 5

    EC2实例无法在浏览器中访问

  6. 6

    带有Rails4的浏览器无法访问ec2实例

  7. 7

    访问apache2中的php页面时发生内部服务器错误

  8. 8

    访问apache2中的php页面时发生内部服务器错误

  9. 9

    无法通过在centos 7上配置的浏览器访问vsftp服务器

  10. 10

    在Windows上用PHP模块启动Apache时出错:“无法将php5apache2_4.dll加载到服务器中:访问被拒绝”

  11. 11

    在Win 7 OS的Safari浏览器中,Bootstrap 2组件已损坏

  12. 12

    使用 api 密钥使用 Web API 时,出现以下错误 - 远程服务器返回错误:(403) Forbidden

  13. 13

    无法在Windows 7中启动服务器服务。错误2:找不到文件

  14. 14

    访问远程服务器IIS7上的虚拟目录时出现运行时错误

  15. 15

    部署(iis7,asp.net mvc4)时,如何使Visual Studio解决方案中的文件夹出现在服务器上?

  16. 16

    无法在 Raspberry Pi 上挂载 Synology 服务器,但可以在文件浏览器中访问它(挂载错误(2):没有这样的文件或目录)

  17. 17

    引导时出现“ psycopg2.OperationalError:无法连接到服务器:连接被拒绝”错误

  18. 18

    引导时出现“ psycopg2.OperationalError:无法连接到服务器:连接被拒绝”错误

  19. 19

    在IIS中部署.NET Core RC2时出现服务器错误502

  20. 20

    调用服务器到服务器CloudKit Web服务时出现授权错误

  21. 21

    尝试对客户端服务器ssl进行身份验证时,Tomcat 7获取SSLv2Hello被禁用错误

  22. 22

    获取“检测到GTK + 2.x符号”。尝试使用CommandBox启动服务器时出现错误

  23. 23

    尝试使用 eclipse juno 服务器运行 struts2 时,出现 HTTP 状态 404 错误

  24. 24

    从远程服务器提交neo4j批处理时出现IncompleteRead错误;格式错误的HTTP响应

  25. 25

    从远程服务器提交neo4j批处理时出现IncompleteRead错误;格式错误的HTTP响应

  26. 26

    将SSL请求从Apache服务器转发到Tomcat时出现403(禁止)错误

  27. 27

    Install4j:在 CentOS 7 服务器中执行安装程序无法启动并出现异常

  28. 28

    通过AJAX POST请求将大型文件传递到服务器时发生错误(IIS 7,ASP.NET MVC 4)

  29. 29

    创建Gradle项目时出现错误:服务器返回了HTTP响应代码:403

热门标签

归档