鍍金池/ 問答/PHP  Linux  HTML/ laravel nginx 下配置 https 訪問路徑問題

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這一段被放開,會出現(xiàn)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文件

回答
編輯回答
安若晴

放出 Laravel5.5 的 nginx 官方推薦配置,其中加上了 https 跳轉(zhuǎn)的代碼,但是 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 配置學習

2017年5月29日 22:16
編輯回答
下墜

還有個前提,http 怎么都行,就https不行

2017年4月13日 23:12