如何解决Apache中的403禁止错误?

时间:2019-08-22 11:19:55

标签: apache xampp http-status-code-403

我正在服务器端工作,我遇到了问题。我在服务器中使用XAMPP和Apache服务器。首先,我购买了一个静态IP,然后打开端口以供所有人访问。

在以下情况下我可以成功:“ http:// {StaticIP} / api / NewsJson” 。但是,当我尝试“ https:// {StaticIP} / api / NewsJson” 时,浏览器出现403错误。我搜索并找到了解决方法。

首先,我更改“ xampp \ apache \ conf \ extra \ httpd-xampp” 文件夹中的行。我更改了本地授予的更改,要求全部授予。

ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
    AllowOverride None
    Options None
    Require all granted
    <Files "php-cgi.exe">
          Require all granted
    </Files>
</Directory>

<Directory "C:/xampp/cgi-bin">
    <FilesMatch "\.php$">
        SetHandler cgi-script
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler None
    </FilesMatch>
</Directory>

<Directory "C:/xampp/htdocs/xampp">
    <IfModule php7_module>
        Require all granted
        <Files "status.php">
            php_admin_flag safe_mode off
        </Files>
    </IfModule>
    AllowOverride AuthConfig
</Directory>

<IfModule alias_module>
    Alias /licenses "C:/xampp/licenses/"
    <Directory "C:/xampp/licenses">
        Options +Indexes
        <IfModule autoindex_color_module>
            DirectoryIndexTextColor  "#000000"
            DirectoryIndexBGColor "#f8e8a0"
            DirectoryIndexLinkColor "#bb3902"
            DirectoryIndexVLinkColor "#bb3902"
            DirectoryIndexALinkColor "#bb3902"
        </IfModule>
    Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
   </Directory>

    Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
    <Directory "C:/xampp/phpMyAdmin">
        AllowOverride AuthConfig
    Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

    Alias /webalizer "C:/xampp/webalizer/"
    <Directory "C:/xampp/webalizer">
        <IfModule php7_module>
            <Files "webalizer.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
    Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>
</IfModule>

然后,将此行添加到“ xampp \ apache \ conf \ extra \ httpd-vhosts” 文件夹中。

    <VirtualHost *:80>
                DocumentRoot "C:/xampp/htdocs/api/NewsJson"
                ServerName 192.168.*.** (My Server IP)
                <Directory "C:/xampp/htdocs/api/NewsJson">
                    Options Indexes FollowSymLinks Includes ExecCGI
                    AllowOverride All
                    Order allow,deny
                    Allow from all
                    Require all granted
                </Directory>
            </VirtualHost>

    <VirtualHost *:443>
            DocumentRoot "C:/xampp/htdocs/api/NewsJson"
                ServerName 192.168.*.** (My Server IP)
                <Directory "C:/xampp/htdocs/api/NewsJson">
                    Options Indexes FollowSymLinks Includes ExecCGI
                    AllowOverride All
                    Order allow,deny
                    Allow from all
                    Require all granted
                </Directory>
            </VirtualHost>

<VirtualHost *:443>
 DocumentRoot "C:/xampp/htdocs/api/NewsJson"
 ServerName 192.168.*.** (My Server IP)
 SSLEngine on
 SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
 SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
</VirtualHost>

然后更改我的“。htaccess” 文件夹。

RewriteEngine On
RewriteRule NewsJson.html$ NewsJson.php [L]

更改它们时,我关闭了Apache,然后再次打开。但是,我仍然采取403禁止的错误。我该怎么解决?

AH00112: Warning: DocumentRoot [C:/xampp/htdocs/api/NewsJson] does not exist
AH00112: Warning: DocumentRoot [C:/xampp/htdocs/api/NewsJson] does not exist
[Thu Aug 22 14:47:29.161955 2019] [ssl:warn] [pid 5332:tid 384] AH01909: StaticIP:80:0 server certificate does NOT include an ID which matches the server name
[Thu Aug 22 14:47:29.161955 2019] [ssl:warn] [pid 5332:tid 384] AH01915: Init: (StaticIP:80) You configured HTTPS(443) on the standard HTTP(80) port!

1 个答案:

答案 0 :(得分:0)

为了能够在浏览器中通过HTTPS访问项目,必须首先在Apache服务器上设置SSL证书。 XAMPP本身不执行此操作,因此此时您必须手动执行操作。

这是如何工作的,在有关如何为本地XAMPP项目设置SSL / HTTPS的教程中进行了说明。 https://www.askingbox.com/tutorial/xampp-how-to-set-up-ssl-https-for-local-projects

相关问题