V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
linar
V2EX  ›  NGINX

nginx 部署 thinkphp3.2.3 遇到的问题

  •  
  •   linar · 2016-01-27 22:41:59 +08:00 · 5656 次点击
    这是一个创建于 3014 天前的主题,其中的信息可能已经有所发展或是发生改变。

    环境:阿里云 ubuntu 14.04 nginx 1.8.0 php 5.5.9 , 有虚拟主机,已经安装多个应用

    安装 weiphp 的时候,查了很多,得知 nginx 不支持 phpinfo,rewrite,,,也不太懂。然后安装的时候可以打开安装页面,但是点击同意协议的时候,跳转路径不正常:
    http://xx.cn.php/?s=/install/step1.html(但是如果手动改成 http://xx.cn/install.php?s=/install/step1.html 的话就可以看到检测环境页面,只不过下一步也失败)
    情况就是这样,求教...大概设置了一下本应用的配置文件如下:

    server {

    listen       80;
    server_name xx.cn  www.xx.cn;
    root /var/www/xx/html/;
    index  index.php index.html index.htm;
    access_log /var/www/xx/logs/access.log;
    error_log /var/www/xx/logs/error.log;
    
    location / {
         try_files $uri $uri/ /index.php;
    }
    location ~ \.php$ {
        include fastcgi_params;
        set $real_script_name $fastcgi_script_name;
    
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
            set $real_script_name $1;
            set $path_info $2;
            }
        fastcgi_param  SCRIPT_FILENAME /var/www/xx/html$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_read_timeout 240;
    
    }
    

    }

    8 条回复    2016-01-28 10:28:06 +08:00
    just1
        1
    just1  
       2016-01-27 22:55:15 +08:00 via Android
    phpinfo 什么时候和 htto 服务器有关了😓nginx 支持 rewrite 啊
    just1
        2
    just1  
       2016-01-27 22:55:29 +08:00 via Android
    @just1 o –>p
    squid157
        3
    squid157  
       2016-01-27 22:57:43 +08:00 via iPhone
    @just1 支持的函数跟 nginx 确实没关系 但 rewrite 跟 Apache 很不一样,至少不能像以前那样搞个 htaccess 完事儿 而去 rewrite 规则也是配置好了改动只能重启
    realpg
        4
    realpg  
       2016-01-27 23:14:51 +08:00
    我觉得对于楼主来说还是回归 apache 能省事一些……
    zeac
        5
    zeac  
       2016-01-27 23:20:36 +08:00
    参考 TP 手册 url_rewrite 部分

    也就是把你上面配置文件***location /***部分做修改
    linar
        6
    linar  
    OP
       2016-01-27 23:27:18 +08:00
    @zeac 能否讲解一下原因,链接为何会成为这样: http://xx.cn.php/?s=/install/step1.html
    zeac
        7
    zeac  
       2016-01-27 23:34:23 +08:00
    @linar 搜索 rewrite 。
    简单的说, location 那一部分就是修饰 url 的,可以说是为了好看。
    你要是认真学了 tp 应该知道 tp 有三种 url 形式,其中有一种还是两种就是要靠重写规则实现。
    再说简单点,很多 CMS 、 framework 什么的就是通过重写规则将 index.php 给隐藏的。

    以上如有错误欢迎楼下指正。
    withrock
        8
    withrock  
       2016-01-28 10:28:06 +08:00
    我觉得你的 location 写的不对.
    如果你是最终的请求路径是这样的:/xxx/demo.php/archive/1 ,
    那么你的 location 应该这样写:
    location ~ .*\.php(\/.*)*$ {
    因为 demo.php 后面的东西是$2
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5502 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:01 · PVG 17:01 · LAX 02:01 · JFK 05:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.