首页 > 解决方案 > 无法访问在具有虚拟主机的 Windows 10 wsl 上运行的 Nginx

问题描述

所以我决定在带有 WSL 的 Windows 10 上安装 ubuntu 20。默认情况下,它带有我删除并设置为默认 nginx 的 Apache。当我尝试localhost从我的 Windows 访问时,我得到了 nginx 默认页面(它工作正常)。但是在我的虚拟机上,我添加了一个无法从 Windows 机器打开的虚拟主机。当我尝试访问server_name我在虚拟机的主机文件和 Windows 的主机文件中添加的内容时,我不能。

这是我的虚拟主机配置文件。

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

    server_name admin.finestgreens.local www.admin.finestgreens.local;

    root /home/melomancheto/www/shop-admin/public;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

}

我检查了 fpm 路径,如果.sock文件存在并且它在那里。我有以下配置sites-available 在此处输入图像描述

这是我的符号链接sites-enabled

在此处输入图像描述

我检查过,我nginx的运行正常,我的php-fpm.

这是我在 Linux 和 Windows 机器上的 hosts 文件

在此处输入图像描述

我错过了一些东西,但我不知道是什么..

This site can’t be reachedCheck if there is a typo in admin.finestgreens.local.
If spelling is correct, try running Windows Network Diagnostics.
DNS_PROBE_FINISHED_NXDOMAIN

这是我尝试访问我的server_name.

问题已解决,我的网址有错字 xD

标签: nginxvirtual-machinevirtualhostwindows-subsystem-for-linux

解决方案


推荐阅读