Mac上的Nginx虚拟块指向localhost的index.php

我正在配置虚拟主机以在我的 mac 上为 .localhost 域提供服务。但是当我在浏览器中打开“project.localhost”时,它显示的页面与浏览 localhost 的索引相同。(ps:我还配置了 dnsmasq 和 /etc/hosts)。(试图提供 index.php)


这是我的 nginx.conf:


worker_processes  1;



events {

    worker_connections  1024; }



http {

    include       mime.types;

    default_type  application/octet-stream;

    server_names_hash_bucket_size 64;


    client_max_body_size 50M;

    sendfile        on;

    keepalive_timeout  65;


    server {

        listen       80;

        server_name  localhost;

        root   html;


        location / {

            # root   html;

            index index.php index.html index.htm;

        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            # root   html;

        }


        location ~ \.php$ {

            # root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            fastcgi_param  SCRIPT_FILENAME $request_filename;

            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

    }


    include servers/*; }

这是可用的站点:


    server {

        listen 80;

        listen project.localhost:80;

        server_name project.localhost;


        location / {

            root html/project.localhost/public_html;

            index index.php index.html index.htm;

            try_files $uri $uri/ =404;

        }

}


但是当我在浏览器中浏览 project.localhost 时,它会显示与 localhost/index.php 相同的页面。我究竟做错了什么?


繁星点点滴滴
浏览 96回答 1
1回答

杨__羊羊

正如@Richard 在评论部分中提到的那样,我能够通过在 我的 nginx.conf 中包含sites-available/*.conf:来解决这个问题。谢谢@理查德include /usr/local/etc/nginx/sites-available/*.confinclude server/*
打开App,查看更多内容
随时随地看视频慕课网APP