Laravel Nginx配置步骤详解

这是一个Laravel框架运行nginx服务器的配置示例,Laravel框架版本5.2.

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. root /usr/share/nginx/html/tanteng.me/public;
  5. index index.php index.html index.htm;
  6. #charset koi8-r;
  7. #access_log /var/log/nginx/log/host.access.log main;
  8. location / {
  9. try_files $uri $uri/ /index.php?$query_string;
  10. }
  11. #error_page 404 /404.html;
  12. # redirect server error pages to the static page /50x.html
  13. #
  14. error_page 500 502 503 504 /50x.html;
  15. location = /50x.html {
  16. root /usr/share/nginx/html/tanteng.me/public;
  17. }
  18. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  19. #
  20. #location ~ \.php$ {
  21. # proxy_pass http://127.0.0.1;
  22. #}
  23. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  24. #
  25. location ~ \.php$ {
  26. fastcgi_pass 127.0.0.1:9000;
  27. fastcgi_index index.php;
  28. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  29. include fastcgi_params;
  30. }
  31. # deny access to .htaccess files, if Apache's document root
  32. # concurs with nginx's one
  33. #
  34. location ~ /\.ht {
  35. deny all;
  36. }
  37. }

运行在CentOS 7环境,Nginx版本1.8.