使用 style apache2 userdir配置 nginx



我只需要用 apache2 样式配置我的 nginx 服务器user_dir

我有我的配置文件,这些部分:

   location ~ .php$ {
                include snippets/fastcgi-php.conf;
                 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
  location ~ ^/~(.+?)(/.*)?$ {
             alias /home/$1/public_html$2;
            index  index.php index.html index.htm;
            autoindex on;
        }

这部分有效,我看到目录,索引.html,但索引.php不起作用。

哪种配置应该正确?谢谢。

从不同的根运行 PHP(即 /home/$1/public_html$2 (,您将需要使用嵌套的位置块。

例如:

location ~ ^/~(.+?)(/.*)?$ {
    alias /home/$1/public_html$2;
    index  index.php index.html index.htm;
    autoindex on;
    location ~ .php$ {
        if (!-f $request_filename) { return 404; }
        include        ...;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
        fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
    }
}
location ~ .php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

请注意,$request_filename用作别名文件的路径。位置的顺序需要颠倒(如上图所示(,以便正确的位置处理以 .php 结尾的 URI。有关详细信息,请参阅此文档。

您应该添加相应的include语句。snippets/fastcgi-php.conf文件可能合适,否则使用 include fastcgi_params;

最新更新