0

我正在 Laravel 5.2 中建立一个网站,而不是从头开始建立一个论坛,我希望安装一个诸如SMF之类的。

Laravel 当前位于我的 Web 服务器的根目录中,我希望将其保留在那里,因为我希望将 SMF 安装在一个文件夹中。

例如:www.example.com/smf

我正在考虑将它安装在 Laravel 的/public文件夹中,但我担心它们会相互冲突。该/public文件夹是否是安装 SMF 的正确位置,我应该使用指向 SMF 文件夹的路由吗?

服务器:通过 Laravel Forge 的 DO droplet

4

2 回答 2

1

您可以使用 Nginx 重定向www.example.com/smf到您的 SMF 安装。为此,请将其添加到您的server块中:

location /smf {
    # nginx will concatenate the string above with the root value
    # so your SMF files should be in "/path/to/smf/parent/dir/smf".
    # Make sure that Nginx can access them.
    root "/path/to/smf/parent/dir";

    # change this config to suit your needs
    index  index.php index.html index.htm;

    location ~ \.php$ {

        # Here use the same config from the server block that allows you
        # to execute PHP scripts
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

我应该补充几点:

  • 在编辑之前备份配置文件。
  • 尽管我已经尝试了上面的代码(并且它在我的机器上运行),但我必须说我不是 Nginx 专家。
于 2016-04-02T20:30:52.490 回答
1

您需要在Laravel 相关规则之前为要使用的文件夹添加自定义规则:

location /smf/index.php(/.*)?$ {        
    fastcgi_split_path_info ^(/smf/index.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout 1000;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
}
location /smf/ { 
    if (!-e $request_filename) {
            rewrite ^.*$ /smf/index.php last;    
        }
    try_files $uri $uri/ smf/index.php?args; 
}

在此处查找示例 nginx 配置文件

于 2016-04-03T03:57:08.740 回答