nginx上部署thinkphp的解決辦法

來源:互聯網
上載者:User
nginx上部署thinkphp的解決方案

nginx上部署thinkphp的解決方案

?

最近在用thinkphp做個小東西,基本完成後部署到nginx伺服器上才發覺nginx是不支援pathinfo的,網上搜尋了別人的解決方案,有兩種思路:
1、修改thinkphp讓他可以在nginx上運行
2、修改nginx讓它支援pathinfo

網上說nginx開啟pathinfo是有一定風險的,能不用pathinfo最好不用,所以還是折騰thinkphp吧,個人覺得這種方法相對第2種方法來得簡單

修改nginx的rewrite

location /
{
index index.php;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /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_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php?IF_REWRITE=1;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}

然後項目配置下url模式改為2

'URL_MODEL'=>2,

如果是多重專案,布署項目時要把項目布署到目錄裡,如背景項目放到Admin目錄裡,那麼在nginx的rewrite裡再寫一條

?

location?/XXX/?{
if?(!-e?$request_filename)?{
rewrite??^/XXX/(.*)$??/XXX/index.php?s=$1??last;
break;
}
}

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.