hi我是一个laravel开发人员。在envato工作。我有一些拉拉威尔的项目。我想为我的laravel项目做一个自定义配置。
示例
-
http://demo.jubayed.com/demo1/
-
http://demo.jubayed.com/demo2/
-
http://demo.jubayed.com/demo3/
-
http://demo.jubayed.com/demo4/
-
http://demo.jubayed.com/demo5/
root demo.jubayed.com/$demoProject/
server {
listen 80;
server_name demo.jubayed.com;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location /($demoProject)/ {
try_files $uri $uri/ /index.php?$query_string;
root /var/www/$demoProject/public;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location = /sitemap.xml { access_log off; log_not_found off; }
error_page 404 /index.php;
# error_page 500 /index.php;
# error_page 401 /index.php;
# error_page 403 /index.php;
location ~ .php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.(?!well-known).* {
deny all;
}
}
您可能需要使用alias
而不是root
,因为您需要操作URI以将public
插入路径名中。有关详细信息,请参阅本文档。
您还需要为PHP使用嵌套的location
,因为它需要访问相同的路径名。
location ~ ^/(?<project>[^/]+)/(?<suffix>.*)$ {
alias /var/www/$project/public/$suffix;
if (!-e $request_filename) { rewrite ^ /$project/index.php last; }
location ~ .php$ {
if (!-f $request_filename) { return 404; }
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
由于长期问题,我避免在同一块中使用try_files
和alias
。关于if
的使用,请参阅此注意事项。