小伙伴在使用ThinkPHP搭建自己或者公司項(xiàng)目的時(shí)候均函,url模式設(shè)置成為兼容模式称龙,也就是URL_MODEL的值為3的時(shí)候是不是也遇到過Lnmp的環(huán)境不支持pathinfo模式炭臭,當(dāng)然了PHP+Nginx+Linux+Mysql的小伙伴呢狂打,就不用看了伴栓!
下面就教大家怎么講我們的各種云服務(wù)器下lnmp的環(huán)境支持pathinfo牡借,說到這里是不是有的小伙伴可能不太明白pathinfo模式是什么拳昌,下面小編就先給大家上個(gè)個(gè)小例子:
www.xxx.com/index.php/Admin/Manager/Login
這樣的url形式就是pathinfo的模式,這樣的模式更加利于百度小蜘蛛的識(shí)別钠龙,也就是更加優(yōu)于SEO炬藤。
下面就是重點(diǎn)步驟了,小伙伴們要注意了:
實(shí)際上差不多就是把nginx.conf拆解下來
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è)地址要和你的訪問地址相對(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就可以找到我們了