当前位置:酷酷问答>生活百科>Linux下pathInfo的配置说明(Thinkphp)

Linux下pathInfo的配置说明(Thinkphp)

2024-12-09 19:50:55 编辑:zane 浏览量:588

Linux下pathInfo的配置说明(Thinkphp)

的有关信息介绍如下:

Linux下pathInfo的配置说明(Thinkphp)

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

下面思梦PHP就教大家怎么讲我们的各种云服务器下lnmp的环境支持pathinfo,说到这里是不是有的小伙伴可能不太明白pathinfo模式是什么,下面小编就先给大家上个个小例子:

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

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

下面就是重点步骤了,小伙伴们要注意了:

实际上差不多就是把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的小伙伴

版权声明:文章由 酷酷问答 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.kukuwd.com/life/159371.html
热门文章