網(wǎng)站開發(fā)主要用什么語言武漢seo關鍵詞排名優(yōu)化
一般情況下,當用戶安裝云鎖的時候,云鎖會自動適配nginx版本,使用我們已經(jīng)預編譯好的包含云鎖模塊的nginx備份并替換掉您當前系統(tǒng)中使用的nginx。卸載時,會將系統(tǒng)原始nginx文件替換回來。因此,云鎖可保護使用nginx搭建的網(wǎng)站,開創(chuàng)了這個領域的先河。 我們秉承著讓安全變得更簡單的宗旨,使云鎖盡可能多的適配廣大用戶的nginx版本(目前無法覆蓋所有nginx版本),決定開放云鎖nginx模塊的源碼,讓有能力的小伙伴們自己動手同云鎖一起打造一個安全的nginx環(huán)境。
一 、編譯云鎖nginx模塊
步驟如下:
1.為避免意外情況發(fā)生, 請先將系統(tǒng)當前使用中的nginx進行備份(包括相關的網(wǎng)站配置文件)
2.wget https://codeload.github.com/yunsuo-open/nginx-plugin/zip/master -O nginx-plugin-master.zip
3.unzip nginx-plugin-master.zip
4.cd nginx-plugin-master
5.pwd 獲取當前云鎖插件源碼所在目錄的全路徑 (假設為:/home/nginx-plugin-master,實際情況以pwd輸出為準)
6.以下兩種情況, 可以跳過這一步驟: 1)您的 nginx 是 tengine。 2)nginx 版本大于等于 1.8.0 并且 安裝的云鎖為V3, 此時需要關注 第 8 條說明。
除以上兩種情況,對于 nginx 來說,由于其不支持post過濾,所以需要修改nginx源碼目錄下src/http/ngx_http_upstream.c 文件,步驟如下:
a.查找 static void ngx_http_upstream_init_request(ngx_http_request_t *r)函數(shù),在其所在行上方添加:int ngx_http_yunsuo_post_in_handler(ngx_http_request_t *r);
b.在ngx_http_upstream_init_request函數(shù)開頭,變量聲明后,添加:
if(ngx_http_yunsuo_post_in_handler(r)) {return;}
以nginx-1.0.11為例:
修改前源碼:
static voidngx_http_upstream_init_request(ngx_http_request_t *r){ngx_str_t *host;ngx_uint_t i;ngx_resolver_ctx_t *ctx, temp;ngx_http_cleanup_t *cln;ngx_http_upstream_t *u;ngx_http_core_loc_conf_t *clcf;ngx_http_upstream_srv_conf_t *uscf, **uscfp;ngx_http_upstream_main_conf_t *umcf;if (r->aio) {return;}u = r->upstream;......}
修改后源碼:
/*這段是添加的*/int ngx_http_yunsuo_post_in_handler(ngx_http_request_t *r);/*------------*/static voidngx_http_upstream_init_request(ngx_http_request_t *r){ngx_str_t *host;ngx_uint_t i;ngx_resolver_ctx_t *ctx, temp;ngx_http_cleanup_t *cln;ngx_http_upstream_t *u;ngx_http_core_loc_conf_t *clcf;ngx_http_upstream_srv_conf_t *uscf, **uscfp;ngx_http_upstream_main_conf_t *umcf;/*這段是添加的*/if(ngx_http_yunsuo_post_in_handler(r)) {return;}/*------------*/if (r->aio) {return;}u = r->upstream;......}
7.云鎖的nginx插件模塊是標準的nginx模塊,所以您在編譯nginx過程中,configure時只要添加額外參數(shù)–add-module=/home/nginx-plugin-master(注意:/home/nginx-plugin-master為示例,實際路徑以步驟5中pwd命令為準)即可讓nginx支持云鎖的功能,示例如下:
假設您之前configure時的命令如下:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module \--with-http_ssl_module --with-http_gzip_static_module \--add-module=../ngx_cache_purge-1.3
現(xiàn)在的configure時的命令如下:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module \--with-http_ssl_module --with-http_gzip_static_module \--add-module=../ngx_cache_purge-1.3 --add-module=/home/nginx-plugin-master
8、以下兩種情況, 跳過此步驟:
1)您的 nginx 是 tengine。
2)在步驟 6 中 已經(jīng)做過了配置。 當您的 nginx 版本大于等于 1.8.0 并且安裝的云鎖為V3時,想要支持 POST 防護, 只需在 configure 生成的 Makefile (即 objs/Makefile 文件)中 CFLAGS 追加宏定義 HIGHERTHAN8 形如 : CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
修改為:CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DHIGHERTHAN8
9、編譯 nginx (注意:如果原本已經(jīng)有 nginx, 只執(zhí)行 make 即可,make install 會覆蓋掉你的 nginx.conf)
10、將系統(tǒng)當前使用中的nginx二進制文件替換為剛剛編譯好的包含了云鎖模塊的nginx文件即可
二 、讓云鎖識別您自己編譯的nginx(V3版本云鎖不需要執(zhí)行此步驟)
1、安裝云鎖,如果您已經(jīng)安裝了云鎖,可跳過此步驟。如果還沒有,請到http://www.yunsuo.com.cn/ht/software/下載并安裝云鎖
2、cd /usr/local/yunsuo_agent/nginx/
3、./configure_compile_nginx nginx_install_path (nginx_install_path為nginx的安裝路徑,即configure時 --prefix=path如果未指定過路徑, 那么默認為/usr/local/nginx)