duandu5846 2018-07-24 12:10
浏览 65

如何使用通配符使用nginx部署laravel

I want to deploy my laravel application with nginx using wildcard domain. But that not work correctly. I have this error:

Corrupted Content Error

The site at http://www.exemple.com/ has experienced a network protocol violation that cannot be repaired. The page you are trying to view cannot be shown because an error in the data transmission was detected. Please contact the website owners to inform them of this problem.

An example for my laravel routing

<?php

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

This is my nginx configuration:

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算