虚拟机域名指向共享文件夹404的问题

环境:

vmware
php7
nginx
mysql
laravel

挂载目录 /mnt/hgfs/WWW/test/l/public

首先是/usr/local/nginx/conf/vhost 下的test.com.conf

server
{
    listen 80;
    #listen [::]:80;
    server_name test.com test2.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /mnt/hgfs/WWW/test/l/public;

    include rewrite/laravel.conf;
    #error_page   404   /404.html;

    # Deny access to PHP files in specific directory
    #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

    include enable-php-pathinfo.conf;

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /\. {
        deny all;
    }

    access_log off;
}

接下来是windows的host文件

192.168.0.16 test.com

问题:此时使用游览器访问test.com出现了404,域名指向挂载目录是行不通的吗,还是我配置错了?求大神

阅读 2.9k
2 个回答

缺少nginx 与 php 通讯的地方

   location ~ \.php(.*)$  {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

Nginx 服务器无法直接与 FastCGI 服务器(也就是php-fpm)进行通信,本身不能识别php,需要启用 ngx_http_fastcgi_module 模块进行代理配置,才能将请求发送给 FastCGI 服务。

fastcgi_pass 用于设置 FastCGI 服务器的 IP 地址(TCT 套接字)或 UNIX 套接字。 fastcgi_param 设置传入 FastCGI 服务器的参数。

先linux下查看php-fpm开启了没有

ps aux | grep php-fpm

然后nginx 加入下面配置。

 location ~ \.php$ {
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
 }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题