Nginx下WEBshell跨站配置方法

來源:互聯網
上載者:User

作者親測,需要更改php來源程式後,重新編譯php。在使用fpm方式安裝時,打補丁過程中會修改php的檔案,所以需要在打完fpm補丁後再修改php來源程式。

tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/

 代碼如下 複製代碼

vi  main/fopen_wrappers.c


/* {{{ php_check_open_basedir
*/
PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC)
{
        /* Only check when open_basedir is available */
        if (PG(open_basedir) && *PG(open_basedir)) {
                char *pathbuf;
                char *ptr;
                char *end;

// 添加的內容開始

               char *env_document_root = sapi_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
                if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) {
                        efree(env_document_root);
                        return 0;
                }

                // 添加的內容結束

                pathbuf = estrdup(PG(open_basedir));

                ptr = pathbuf;

                while (ptr && *ptr) {
                        end = strchr(ptr, DEFAULT_DIR_SEPARATOR);
                        if (end != NULL) {
                                *end = '';
                                end++;
                        }

                        if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) {
                                efree(pathbuf);
                                return 0;
                        }

                        ptr = end;
                }
                if (warn) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s)", path, PG(open_basedir));
                }
                efree(pathbuf);
                errno = EPERM; /* we deny permission to open it */
                return -1;
        }

        /* Nothing to check... */
        return 0;
}


在5.3.3以上已經增加了HOST配置,可以起到防跨站、跨目錄的問題。如果你是PHP 5.3.3以上的版本,可以修改/usr/local/php/etc/php.ini在末尾裡加入:

 代碼如下 複製代碼


[HOST=www.111cn.net]
open_basedir=/home/wwwroot/www.111cn.net/:/tmp/
[PATH=/home/wwwroot/www.111cn.net]
open_basedir=/home/wwwroot/www.111cn.net/:/tmp/


然後重啟nginx和php-fpm

然後用中國菜刀等工具測試即可發現Nginx已經支援防跨站

小提示,如果你網站沒有大量的流量或html靜態頁面,我還是建義你使用apache來實配置網站,這樣就不存在此問題了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.