nginx.conf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. server {
  2. # 监听 HTTP 协议默认的 [80] 端口。
  3. listen 80;
  4. # 绑定主机名 [example.com]。
  5. server_name localhost;
  6. # 服务器站点根目录 [/example.com/public]。
  7. root /app/public;
  8. # 添加几条有关安全的响应头;与 Google+ 的配置类似,详情参见文末。
  9. add_header X-Frame-Options "SAMEORIGIN";
  10. add_header X-XSS-Protection "1; mode=block";
  11. add_header X-Content-Type-Options "nosniff";
  12. # 站点默认页面;可指定多个,将顺序查找。
  13. # 例如,访问 http://example.com/ Nginx 将首先尝试「站点根目录/index.html」是否存在,不存在则继续尝试「站点根目录/index.htm」,以此类推...
  14. index index.html index.htm index.php;
  15. # 指定字符集为 UTF-8
  16. charset utf-8;
  17. # Laravel 默认重写规则;删除将导致 Laravel 路由失效且 Nginx 响应 404。
  18. location / {
  19. try_files $uri $uri/ /index.php?$query_string;
  20. }
  21. # 关闭 [/favicon.ico] 和 [/robots.txt] 的访问日志。
  22. # 并且即使它们不存在,也不写入错误日志。
  23. location = /favicon.ico { access_log off; log_not_found off; }
  24. location = /robots.txt { access_log off; log_not_found off; }
  25. # 将 [404] 错误交给 [/index.php] 处理,表示由 Laravel 渲染美观的错误页面。
  26. error_page 404 /index.php;
  27. # URI 符合正则表达式 [\.php$] 的请求将进入此段配置
  28. location ~ \.php$ {
  29. # 配置 FastCGI 服务地址,可以为 IP:端口,也可以为 Unix socket。
  30. fastcgi_pass phpfpm:9000;
  31. # 配置 FastCGI 的主页为 index.php。
  32. fastcgi_index index.php;
  33. # 配置 FastCGI 参数 SCRIPT_FILENAME 为 $realpath_root$fastcgi_script_name。
  34. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  35. # 引用更多默认的 FastCGI 参数。
  36. include fastcgi_params;
  37. }
  38. # 通俗地说,以上配置将所有 URI 以 .php 结尾的请求,全部交给 PHP-FPM 处理。
  39. # 除符合正则表达式 [/\.(?!well-known).*] 之外的 URI,全部拒绝访问
  40. # 也就是说,拒绝公开以 [.] 开头的目录,[.well-known] 除外
  41. location ~ /\.(?!well-known).* {
  42. deny all;
  43. }
  44. }