小伙伴在利用ThinkPHP搭建自己或者公司项目的时候,url模式设置成为兼容模式,也便是URL_MODEL的值为3的时候是不是也碰着过Lnmp的环境不支持pathinfo模式!

下面思梦PHP请教大家怎么讲我们的各种云做事器下lnmp的环境支持pathinfo,说到这里是不是有的小伙伴可能不太明白pathinfo模式是什么,下面

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

这样的url形式便是pathinfo的模式,这样的模式更加利于百度小蜘蛛的识别,也便是更加优于SEO。

linux里php的infoLinux下pathInfo的设置装备摆设解释Thinkphp Ruby

下面便是重点步骤了,小伙伴们要把稳了:

实际上差不多便是把nginx.conf拆解下来

1,把原有的nginx.conf文件备份(便是修正个名字),然后用下面的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 be opened 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下创建pathinfo.conf(如果已经存在请先备份然后修正)

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,创建重定向 在/usr/local/nginx/conf下创建drect.conf

index index.php;

location ~ \.php$ {

include pathinfo.conf;

break;

}

autoindex on;

3,在/usr/local/nginx/conf里建vhost和conf.d两个文件夹子(mkdir vhost)

在conf.d里创建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文件夹里创建站点配置信息(要以.conf结尾,每次添加新的站点儿时只需修正这里就可以)

server {

listen 80 default_server;

server_name nahan.cn;

//这个地址要和你的访问地址相对应

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,进入 /usr/local/php/etc/php.ini 修正cgi.fix_pathinfo=1

新安装的lnmp如果php版本较低的话须要升级到5.4.27

6,所有文件修正完毕后请重启所有做事。
命令:/root/lnmp restart 新版的重启命令为:lnmp restart

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