如何使用通配符使用Nginx部署Laravel

时间:2018-07-24 12:10:47

标签: php laravel nginx dns

我想使用通配符域将我的laravel应用程序与nginx一起部署。 但这不能正常工作。我有这个错误:

Corrupted Content Error

http://www.exemple.com/上的站点遇到了无法修复的网络协议冲突。 由于检测到数据传输错误,因此无法显示您要查看的页面。     请与网站所有者联系,以告知他们该问题。

我的Laravel路由示例

<?php

 Route::group(['domain' => "{sub}.exemple.com"], function() {
     // load site content
 });

这是我的nginx配置:

server {
    # Update max body size
    client_max_body_size 20M;

    # SSL configuration
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server ipv6only=on;

    ssl on;
    include /etc/nginx/snippets/self-signed.conf;
    include /etc/nginx/snippets/ssl-params.conf;

    # Route and app index
    root /var/www/site/public;
    index index.php index.html;

    # Make site accessible from https://www.exemple.com
    server_name ~^([a-z]+)\.exemple\.com$;

    location / {
       if ($http_x_forwarded_proto != "https") {
            return 301 https://$1.exemple.com$request_uri;
       }

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SERVER_NAME $host;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* \.(?:ico|gif|jpe?g|png)$ {
        expires 7d;
        add_header Pragma public;
        add_header Cache-Control "public";
        access_log off;
    }

    location ~* \.(css|js|ttf)$ {
        expires 1d;
        access_log off;
        add_header Cache-Control "public";
    }
}

0 个答案:

没有答案