VPS侦探论坛

 找回密码
 注册
查看: 7800|回复: 6

[Apache] 关于支持pathinfo

[复制链接]
发表于 2014-7-18 17:31:25 | 显示全部楼层 |阅读模式

这几天想吧thinkphp项目转移到lnmp上运行。发现需要pathinfo,网上查了很多教程(包括论坛的教程),还是没有解决问题。望上天赐我大神,搭救搭救
疑问:在网上说没有配置好
pathinfo最多就是502 ,而我一直是404,是不是有其他问题,付截图

(非
pathinfo
)



(使用后)

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2014-7-18 18:33:10 | 显示全部楼层


自顶一下
大神赶紧出现
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2014-7-18 20:28:57 | 显示全部楼层

1.1 启用pathinfo方法在更新纪录里有http://lnmp.org/changelog.html

其他版本论坛也写过了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2014-7-19 11:17:47 | 显示全部楼层



军哥,我按照更新说说的配置了,还是不行,求帮助附上nginx的配置:
user  www www;

worker_processes auto;

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;

multi_accept on;

}

http

{

include       mime.types;

default_type  application/octet-stream;


server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;


sendfile on;

tcp_nopush     on;


keepalive_timeout 60;


tcp_nodelay on;


fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 256k;


gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

gzip_proxied        expired no-cache no-store private auth;

gzip_disable        "MSIE [1-6]\.";


#limit_conn_zone $binary_remote_addr zone=perip:10m;

##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.


server_tokens off;

#log format

log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';

server

{

listen 81 default;

#listen [::]:80 default ipv6only=on;

server_name www.lnmp.org;

index index.html index.htm index.php;

root  /home/wwwroot/default;


#error_page   404   /404.html;

location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

#try_files $uri =404;

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

fastcgi_index index.php;

include fastcgi.conf;

include pathinfo.conf;

}


location /nginx_status {

stub_status on;

access_log   off;

}


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}


location ~ .*\.(js|css)?$

{

expires      12h;

}


access_log  /home/wwwlogs/access.log  access;

}
include vhost/*.conf;
}
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2014-7-19 13:45:21 | 显示全部楼层

不用改什么,thinkphp 用这个安装包很方便啊..
server
        {
                listen 80;
                #listen [::]:80;
                server_name www.sb.com sb.com;
                if ($host != 'www.sb.com' ) {
                        rewrite ^/(.*)$ http://www.sb.com/$1 permanent;
                }
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/www.sb.com;

                include other.conf;
                #error_page   404   /404.html;
                location / {
                        if (!-e $request_filename) {
                                rewrite  ^(.*)$  /index.php?s=$1  last;
                        }
                }
                location ~ [^/].php(/|$)
                        {
                                # comment try_files $uri =404; to enable pathinfo
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fastcgi.conf;
                                #include pathinfo.conf;
                        }

                location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log  /home/wwwlogs/www.sb.com.log  access;
        }

军哥运维代购:http://shop63846532.taobao.com/

发表于 2014-7-19 13:46:00 | 显示全部楼层

添加vhost的时候 pathinfo 选 other
发表于 2014-7-19 15:15:51 | 显示全部楼层

回复 1# 的帖子


回复楼主,我也是在用 军哥的 lnmp包,

关于 thinkphp 的 pathinfo 让nginx 可以支持,

你可以新建一个 vhost,我将我的 贴给你看,你看着位置 进行改动,一定能正常访问的!

分割线下面,均是新建的vhost,默认路径是 /home/wwwroot/ruan
==================================================
server
        {
                listen       7899;
                server_name 119.146.203.247;
                index index.html index.htm index.php;
                root  /home/wwwroot;

                location /ruan {
                        index index.php;

                        if (!-e $request_filename) {
                                rewrite ^/ruan/(.*)$ /ruan/index.php/$1 last;
                                break;
                        }

                }

                location ~ .+.php($|/) {
                        set $script $uri;
                        set $path_info "/";
                        if ($uri ~ "^(.+.php)(/.+)") {
                                set $script $1;
                                set $path_info $2;
                        }

                        fastcgi_pass  unix:/tmp/php-cgi.sock;
                        fastcgi_index index.php?IF_REWRITE=1;
                        include fcgi.conf;
                        fastcgi_param PATH_INFO $path_info;
                        fastcgi_param SCRIPT_FILENAME /home/wwwroot$fastcgi_script_name;
                        include fastcgi_params;
                }
        }
===================================================================
分割线 结束

然后 - 更改php.ini
#vim /usr/local/php/etc/php.ini

找到:cgi.fix_pathinfo
更改为:cgi.fix_pathinfo=1

最后,记得重启 nginx 和 php-fpm 模块


==============================================

对于thinkphp框架项目的访问格式有多种,其中pathinfo是默认的基本访问格式,
格式为:http://hostname:port/index.php/模块名/action名/参数1/参数1的值/

pathinfo其实就是一个参数,
可以通过$_SERVER['PATH_INFO']获得,
thinkphp框架通过解析它来找到对应的模块和方法。

apache服务器默认是支持pathinfo的,但是nginx服务器默认不支持这种格式


谢谢

[ 本帖最后由 imacintosh 于 2014-7-19 15:18 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-5-3 15:37 , Processed in 0.027965 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表