windows系统本地使用nginx服务,偶尔会出现项目接口报异常错误或者直接404,
解决办法如下:
配置下vhost.conf…
server {
listen 80;
server_name mall.me; #可添加多个,多个之间“空格”分开
#autoindex on;#打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件
location / {
root F:/wnmp/wwwroot/mall;
index index.html index.htm index.php;
#加一下代码即可 if(){}
#此处是伪静态配置
if (!-e $request_filename) {
//此处是针对tp的pathinfo
rewrite ^(.*)$ /index.php?s=$1 last;
//下面是针对其他框架
rewrite ^(.*)$ /index.php/?/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root F:/wnmp/wwwroot;
}
location ~ \.php$ {
root F:/wnmp/wwwroot/mall;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
apache:
在入口文件的同目录下的.htaccess文件 添加
//线上环境配置
server{
listen 80;
root /var/www/mmc-crm/;
index index.html index.php;
server_name xxx.com;
client_max_body_size 200m;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
#rewrite ^(.*)$ /index.php/?/$1 last;
break;
}
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
include snippets/fastcgi-php.conf;
add_header Access-Control-Allow-Origin *;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';
}
access_log /var/log/nginx/api_access.log;
error_log /var/log/nginx/api_error.log;
}