鍍金池/ 問答/PHP  Linux/ 虛擬機(jī)域名指向共享文件夾404的問題

虛擬機(jī)域名指向共享文件夾404的問題

環(huán)境:

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

問題:此時(shí)使用游覽器訪問test.com出現(xiàn)了404,域名指向掛載目錄是行不通的嗎,還是我配置錯(cuò)了?求大神

回答
編輯回答
赱丅呿

Nginx 服務(wù)器無法直接與 FastCGI 服務(wù)器(也就是php-fpm)進(jìn)行通信,本身不能識(shí)別php,需要啟用 ngx_http_fastcgi_module 模塊進(jìn)行代理配置,才能將請(qǐng)求發(fā)送給 FastCGI 服務(wù)。

fastcgi_pass 用于設(shè)置 FastCGI 服務(wù)器的 IP 地址(TCT 套接字)或 UNIX 套接字。 fastcgi_param 設(shè)置傳入 FastCGI 服務(wù)器的參數(shù)。

先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;
 }
2018年9月1日 03:27
編輯回答
假灑脫

缺少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;
        }
2017年7月17日 02:15