最近做微信公衆號的開發,服務器上搭建的是LNMP環境,由於nginx默認是不支持pathinfo的,所以需要修改nginx.conf
注:我直接使用服務器IP進行微信token認證時總是失敗,後來發現是因爲使用了非80端口,不知道小夥伴們是否跟我一樣遇到同樣的問題
另外推薦一個免費內網映射工具:https://natapp.cn/,此乃微信接口調試神器o(∩_∩)o 哈哈!!!
server {
listen 8088;
server_name localhost;
access_log logs/access.log;
error_log logs/error.log;
#root是下面設計到文件路徑的根目錄
root /usr/share/nginx/html;
index index.html index.php;
#定義變量
set $root /usr/share/nginx/html;
#匹配url中server_name之後的部分
location /tp5/public/ {
#重寫url 爲了隱藏tp5中的index.php
if ( !-e $request_filename) {
#將url中server_name之後的部分與 /tp5/public/* 匹配 如果匹配則改寫URl爲/tp5/public/index.php/*
rewrite ^/tp5/public/(.*)$ /tp5/public/index.php/$1 last;
break;
}
}
#pathinfo配置 使支持tp5的標準url
location ~ .+\.php($|/) {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #不支持的改爲:127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
作者:DeFuture
鏈接:http://www.jianshu.com/p/7d9e2b6168ec
來源:簡書
著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。