使用Nginx设置多站点

时间:2019-04-02 08:27:54

标签: laravel nginx multisite

使用nginx设置以下设置时遇到一些问题:

  • example.com
  • example.com/gb/en

这些是laravel网站,gb / en是第一个要添加的网站。根工作于obvs,但我无法使/ gb / en指向/ gb / en / public文件夹。

我尝试了很多事情,但这是我当前的conf文件:

server {
    listen 80;
    listen [::]:80;
    server_name www.example.com;
    root /home/forge/www.example.com/public;

    ssl_protocols TLSv1.2;
    ssl_ciphers TEST;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /gb/en {
        root /home/forge/www.example.com/gb/en/public;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/www.example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

您可以在其中看到我的位置信息块,我曾尝试过多种方法但无济于事。

任何帮助将不胜感激。

编辑:

因此,一旦我意识到url中的子文件夹也被添加到根目录中,便迈出了一步:

location /gb/en/ {
    root /home/forge/www.example.com/public;
    try_files $uri $uri/ /public/index.php?url=$uri;
}

因此,我的文件位于/ public / gb / en / public下,但以上内容解析为/public/gb/en/index.php

如何获取/ gb / en /解析为public / gb / en / public / index.php?

非常感谢;)

编辑:

这个主意突然传给我-使用符号链接!我将/ gb / en链接到单独文件夹中的公用文件夹,并且可以正常工作;)

2 个答案:

答案 0 :(得分:0)

我很乐意将try_files行复制到/en/gb块中。在该文件夹或站点中,您没有像在可行的扩展名中那样指定要使用的扩展名。

尝试一下:

location /gb/en {
    root /home/forge/www.example.com/gb/en/public;
    try_files $uri $uri/ /index.php?$query_string;
}

但是,如果/en/gb的内容与站点有关,那么直接在Laravel中进行设置可能是一个更好的选择。

答案 1 :(得分:0)

我最终使用了符号链接来实现这一目标。我将/ gb / en链接到另一个位置的公用文件夹,它执行了我想要的操作;)

编辑-后来我发现子页面也有问题,但随后找到了该示例,它首先实现了我想要的目标https://gist.github.com/noeldiaz/08a1211a7c47f21f7083

相关问题