Nginx常用来整理web项目配置,做笔记。phpweb项目配置:server{listen80;听[::]:80;#将最大上传大小设置为5MBclient_max_body_size5m;root/srv/www/wechat/public;indexindex.htmlindex.php;服务器名称example.com;位置/{try_files$uri$uri/=404;}#支持php位置~\.php${#在传递之前检查PHP脚本是否存在try_files$fastcgi_script_name=404;fastcgi_indexindex.php;包括fastcgi.conf;#使用php-fpm(或其他unix套接字):fastcgi_passunix:/var/run/php/php7.2-fpm.sock;##使用php-cgi(或其他tcp套接字):#fastcgi_pass127.0.0.1:9000;}#拒绝访问.htaccess文件,如果Apache的文档根#同意nginx的一个#location~/\.ht{denyall;}}phpweb项目配置支持laravel、symfony、Yii2单项:...location/{#首先尝试将请求作为文件提供,然后#作为目录,然后返回显示404。#try_files$uri$uri/=404;#注释上面这句话,使用下面这句话try_files$uri$ur我//index.php?$query_string;}...phpweb项目配置支持ThinkPHP...location~\.php${#regextosplit$urito$fastcgi_script_nameand$fastcgi_pathfastcgi_split_path_info^(.+\.php)(/.+)$;#在传递PHP脚本之前检查它是否存在try_files$fastcgi_script_name=404;#绕过try_files重置$fastcgi_path_info的事实#参见:http://trac.nginx.org/nginx/ticket/321set$path_info$fastcgi_path_info;fastcgi_paramPATH_INFO$path_info;#ThinkPHP依赖环境变量PATH_INFOfastcgi_indexindex.php;包括fastcgi.conf;#使用php-fpm(或其他unix套接字):fastcgi_passunix:/var/run/php/php7.2-fpm.sock;##使用php-cgi(或其他tcp套接字):#fastcgi_pass127.0.0.1:9000;}...phpweb项目配置禁止访问上传目录下的php文件:...#这块的location应该放在location之前~\.php$location~^/uploads/.*\.php${#禁止/uploads文件目录下的所有.php文件访问#denyall;#返回403返回404;#return404}...原文链接:普通nginxweb配置
