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

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘