laravel nginx 下配置 https 访问路径问题

求助, nginx 开启 https 下配置 xx.conf 路径问题
一下是 xx.conf 文件中的 location短

location / {
   index index.html index.htm index.php default.html default.htm default.php forum.php;
   
   #root /home/wwwroot/default/laravel/public;

   try_files $uri $uri/ /index.php?$query_string;
   if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=$1  last;
        break;
   }

}
问题: root /home/wwwroot/default/laravel/public这一段被放开,会出现404的报错,访问不到 laravel/public里的index.php 但是可以访问到.html的文件

但是如果 root /home/wwwroot/default/laravel/public这一段被注释, nginx会自动访问到nginx/html目录。访问正常, index.php index.html均可访问

请问如何才能正常访问到 /home/wwwroot/default/laravel/public 里的php文件

阅读 4.1k
2 个回答

放出 Laravel5.5 的 nginx 官方推荐配置,其中加上了 https 跳转的代码,但是 SSL 的其他配置,请自行添加。

server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    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;
    
    if ($ssl_protocol = "") { return 301 https://$server_name$request_uri; }
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

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

    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;
    }
}

Laravel 5.5 官方推荐 Nginx 配置学习

还有个前提,http 怎么都行,就https不行

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题