Contents that posted a long time ago may be obsolete and may not reflect my current opinion.
以 Laravel 5.8 文档 为准,浅析 Nginx 配置。可作为 轻松部署 Laravel 应用 的拓展阅读。
方便起见,我在注释中使用 []
包裹引用配置中的值。
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;
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_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; }
location ~ /\.(?!well-known).* { deny all; } }
|
关于 X-Frame-Options
、X-XSS-Protection
和 X-Content-Type-Options
可参考 这篇文章,自认为作者讲得还不错,通俗易懂并且是中文。
关于 .well-known
目录的详细解释,可参考 这篇问答(英文)。