与Nginx配合使用(推荐)

示例

  1. gzip on;
  2. gzip_min_length 1024;
  3. gzip_comp_level 2;
  4. gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
  5. gzip_vary on;
  6. gzip_disable "msie6";
  7. upstream laravels {
  8. # 通过 IP:Port 连接
  9. server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=30s;
  10. # 通过 UnixSocket Stream 连接,小诀窍:将socket文件放在/dev/shm目录下,可获得更好的性能
  11. #server unix:/xxxpath/laravel-s-test/storage/laravels.sock weight=5 max_fails=3 fail_timeout=30s;
  12. #server 192.168.1.1:5200 weight=3 max_fails=3 fail_timeout=30s;
  13. #server 192.168.1.2:5200 backup;
  14. keepalive 16;
  15. }
  16. server {
  17. listen 80;
  18. # 别忘了绑Host哟
  19. server_name laravels.com;
  20. root /xxxpath/laravel-s-test/public;
  21. access_log /yyypath/log/nginx/$server_name.access.log main;
  22. autoindex off;
  23. index index.html index.htm;
  24. # Nginx处理静态资源(建议开启gzip),LaravelS处理动态资源。
  25. location / {
  26. try_files $uri @laravels;
  27. }
  28. # 当请求PHP文件时直接响应404,防止暴露public/*.php
  29. #location ~* \.php$ {
  30. # return 404;
  31. #}
  32. location @laravels {
  33. # proxy_connect_timeout 60s;
  34. # proxy_send_timeout 60s;
  35. # proxy_read_timeout 120s;
  36. proxy_http_version 1.1;
  37. proxy_set_header Connection "";
  38. proxy_set_header X-Real-IP $remote_addr;
  39. proxy_set_header X-Real-PORT $remote_port;
  40. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  41. proxy_set_header Host $http_host;
  42. proxy_set_header Scheme $scheme;
  43. proxy_set_header Server-Protocol $server_protocol;
  44. proxy_set_header Server-Name $server_name;
  45. proxy_set_header Server-Addr $server_addr;
  46. proxy_set_header Server-Port $server_port;
  47. proxy_pass http://laravels;
  48. }
  49. }