ThinkPHP->pathinfo模式(Linux下nginx的配置說(shuō)明)

小伙伴在使用ThinkPHP搭建自己或者公司項(xiàng)目的時(shí)候,url模式設(shè)置成為兼容模式,也就是URL_MODEL的值為3的時(shí)候是不是也遇到過(guò)Lnmp的環(huán)境不支持pathinfo模式,當(dāng)然了PHP+Nginx+Linux+Mysql的小伙伴呢,就不用看了!

下面就教大家怎么講我們的各種云服務(wù)器下lnmp的環(huán)境支持pathinfo,說(shuō)到這里是不是有的小伙伴可能不太明白pathinfo模式是什么,下面小編就先給大家上個(gè)個(gè)小例子:

www.xxx.com/index.php/Admin/Manager/Login

這樣的url形式就是pathinfo的模式,這樣的模式更加利于百度小蜘蛛的識(shí)別,也就是更加優(yōu)于SEO。

下面就是重點(diǎn)步驟了,小伙伴們要注意了:

實(shí)際上差不多就是把nginx.conf拆解下來(lái)

1,把原有的nginx.conf文件備份(就是修改個(gè)名字),然后用下面的nginx.conf文件

user www www;

worker_processes 4;

error_log /home/wwwlogs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can beopened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

}

http {

include /usr/local/nginx/conf/mime.types;

default_type text/plain;

log_format main '$remote_addr - $remote_user [$time_local]"$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

access_log off;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

gzip on;

client_max_body_size 20m;

# Load config files from the /etc/nginx/conf.d directory

# The default server is in conf.d/default.conf

include /usr/local/nginx/conf/conf.d/*.conf;

include /usr/local/nginx/conf/vhost/*.conf;

}

2,配置pathinfo在/usr/local/nginx/conf下創(chuàng)建pathinfo.conf(如果已經(jīng)存在請(qǐng)先備份然后修改)

fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param PATH_TRANSLATED$document_root$fastcgi_path_info;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param QUERY_STRING $query_string;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI $document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

#fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;

fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;

fastcgi_param REDIRECT_STATUS 200;

5,創(chuàng)建重定向 在/usr/local/nginx/conf下創(chuàng)建drect.conf

index index.php;

location ~ \.php$ {

include pathinfo.conf;

break;

}

autoindex on;

3,在/usr/local/nginx/conf里建vhost和conf.d兩個(gè)文件夾子(mkdir vhost)

在conf.d里創(chuàng)建default.conf

server {

listen 80;# default_server;

server_name _;

charset utf-8;

#access_log logs/host.access.log main;

location / {

root /usr/share/nginx/html;

index index.html index.htm;

}

error_page 404 /404.html;

location = /404.html {

root /usr/share/nginx/html;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

}

4,在vhost文件夾里創(chuàng)建站點(diǎn)配置信息(要以.conf結(jié)尾,每次添加新的站點(diǎn)兒時(shí)只需修改這里就可以)

server {

listen 80 default_server;

server_name nahan.cn;

//這個(gè)地址要和你的訪問(wèn)地址相對(duì)應(yīng)

root /home/wwwroot/nahan.cn/;

index index.php;

if ($host = nahan.cn) {

rewrite ^/(.*)$ http://www.nahan.cn/$1 permanent;

}

autoindex on;

location / {

try_files $uri $uri/ /index.php$uri;

}

location ~ \.php {

include pathinfo.conf;

break;

}

}

5,進(jìn)入 /usr/local/php/etc/php.ini 修改cgi.fix_pathinfo=1

新安裝的lnmp如果php版本較低的話需要升級(jí)到5.4.27

6,所有文件修改完畢后請(qǐng)重啟所有服務(wù)。命令:/root/lnmp restart 新版的重啟命令為:lnmprestart

小伙伴按照上面的步驟一步一步的配置就可以了,希望這篇文章能幫助那些還在苦于linux下配置pathinfo的小伙伴

更多的精彩內(nèi)容:

小伙伴們可以加群:

思?jí)鬚HP官方交流1群 466388300 思?jí)鬚HP官方交流2群 527490769

作者QQ:476319748

以上聯(lián)系方式備注:微信公眾平臺(tái)思?jí)鬚HP

我們會(huì)定期給大家推送項(xiàng)目實(shí)戰(zhàn)中非常有用的小技巧以及好的思維和小功能的案例!微信搜索思?jí)鬚HP就可以找到我們了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容