WSL2 Nginx-在本地主机上工作,但在127.0.0.1或自定义主机名上抛出403 Forbidden

时间:2020-11-04 20:23:24

标签: php nginx windows-subsystem-for-linux

我一直在尝试在运行Ubuntu 20.04的WSL2上设置Nginx。我几乎完成了整个站点设置。当我访问http:// localhost时,它正在工作。但我希望它位于http://app.test上。所以我将其添加到主机并尝试,它抛出403 Forbidden错误。我没有更改nginx.conf中的任何内容。这是我到目前为止所拥有的:

服务器块

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html/app.test;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

权限

/var/www/html/app.test文件夹属于www-data:www-data用户和组。

主机

我已经在Windows主机和Ubuntu主机中添加了以下内容

127.0.0.1 app.test

发现

  1. 我检查了access.log。我在下面包括了2条日志。第一个是不工作的(访问app.test时),另一个是不工作的(访问localhost时)。
127.0.0.1 - - [05/Nov/2020:00:07:09 +0400] "GET / HTTP/1.0" 403 564 "-" "Mozilla/5.0 (Windows NT 10.0;..."

::1 - - [05/Nov/2020:00:01:13 +0400] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0;...
  1. 我尝试从Windows终端运行curl命令,http://localhost得到200 OK,但http://127.0.0.1却得到403禁止

谢谢!

0 个答案:

没有答案