ngày xưa, cách đó tầm 6,7 năm, tớ trẩu tre đi đọc mấy bài của các anh tin tặc thấy nhắc không ít đến cgi-bin, thiệt sự cho tận bây giờ mới khám phá nó là vật gì mà sao toàn bị hack cầm cố :DBài này sẽ giới thiệu 1 chút về CGI và trả lời debug khi config apache2 bị lỗi (mấy từ bây giờ debug mệt nhọc lắm rồi).Thực hiện tại trên:hvn
lappy: /etc/apache2 $ uname -a; lsb_release -aLinux lappy 3.2.0-30-generic #48-Ubuntu SMP Fri Aug 24 16:52:48 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.Distributor ID: Ubuntu
Description: Ubuntu 12.04.1 LTSRelease: 12.04Codename: precise1. CGI
The CGI (Common Gateway Interface) defines a way for a web server to interact with external content-generating programs, which are often referred khổng lồ as CGI programs or CGI scripts. It is the simplest, & most common, way to put dynamic content on your web site. http://httpd.apache.org/docs/2.2/howto/cgi.html
The Common Gateway Interface (CGI) is a standard (see RFC 3875: CGI Version 1.1) method for web vps software lớn delegate the generation of web nội dung to executable files.

Bạn đang xem: Config apache2 và cgi

Such files are known as CGI scripts; they are programs, often stand-alone applications, usually written in a scripting language.http://en.wikipedia.org/wiki/Common_Gateway_Interface
Như vậy CGI script sẽ là các file chạy được, điều đó phải chăm chú khi debug.Viết script CGI:First, all đầu ra from your CGI program must be preceded by a MIME-type header.
This is HTTP header that tells the client what sort of nội dung it is receiving. Most of the time, this will look like:
Secondly, your đầu ra needs khổng lồ be in HTML, or some other format that a browser will be able khổng lồ display...http://httpd.apache.org/docs/2.2/howto/cgi.html
Một CGI script chỉ cần thoả mãn 2 đk : bắt đầu bằng MIME-type header như làm việc trên, và output ra mã html (nói phổ biến là ra text)Tạo CGI script "hello thon" cùng với 4 ngữ điệu script phổ biến:1.1. PHPKhông đề xuất viết CGI script vị máy tớ đã mua mod cung cấp php rồi, nhằm lúc như thế nào có đk sẽ thử trên sản phẩm công nghệ khác1.2. Python
#!/usr/bin/pythonprint "Content-type: text/html"printprint "hello thon" 1.3. Perl#!/usr/bin/perlprint "Content-type: text/html ";print "Hello, thon." 1.4. TCLlaterrất đơn giản, hiện thời thì chẳng thấy ai buộc phải viết CGI script nữa, dĩ nhiên nó đang là một trong những phần lịch sử rồi.2. Config, debug Apache2cài :sudo apt-get install apache2sau khi mua xong, hãy vào /etc/apache2 nhằm khám phá
Apache2 sau khoản thời gian cài dứt sẽ có một file config đó là `apache2.conf`, 1 file khác là `httpd.conf` với thư mục sites-available/ chứa những file config.Nếu bạn đọc file apache2.conf sẽ thấy có dòng:# Include all the user configurations:Include httpd.conf# Include ports listing
Include ports.conf# Include generic snippets of statements
Include conf.d/# Include the virtual host configurations:Include sites-enabled/hãy xem kỹ file này nhằm biết chỗ đặt config của khách hàng vào đâu. Nếu bạn sử dụng virtual host (không lý giải ở đây), hãy đặt vào `sites-enabled/`, nếu như không, hãy viết vào `httpd.conf`. Nói phổ biến cái này là trường đoản cú do, không người nào ép buộc cả.Sau lúc bạn cài đặt xong bạn cũng có thể phóng vào localhost luôn là bởi vì đã gồm sẵn file config năm vào `sites-available/`, tên là `default` với đã được link (hiểu sơ là chế tạo shortcut sang thư mục `sites-enabled/`Nội dung phần đầu tệp tin này như sau:hvn
localhost Document
Root /var/www
Options Follow
Sym
Links Allow
Override none
Options Indexes Follow
Sym
Links Multi
Views Allow
Override all Order allow,deny allow from all Script
Alias /cgi-bin/ /usr/lib/cgi-bin/
Allow
Override None Options +Exec
CGI -Multi
Views +Sym
Links
If
Owner
Match Order allow,deny Allow from all Error
Log $APACHE_LOG_DIR/error.log
# Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. Log
Level warn Custom
Log $APACHE_LOG_DIR/access.log combinedquay lại chủ đề CGI, các bạn sẽ thấy dòng
Script
Alias /cgi-bin/ /usr/lib/cgi-bin/
hãy đặt các script tại vị trí 1 vào trong thư mục này, chmod bọn chúng thành các file chạy được (chmod a+x tenfile)Sau đó mở trình săn sóc ra với gõ:http://localhost/cgi-bin/index.pyhay http://localhost/cgi-bin/index.pl nhưng xem công dụng hello thon thả ^^ .Toàn cỗ phần trên nói tới việc viết, config CGI script gắng nào mang lại chạy được, nó sẽ là một phần của vượt khứ còn chỉ đọc cho thấy thêm thôi :D .3. Debug apache2.

Xem thêm: Cách dùng index trong excel, cách sử dụng hàm index và match kết hợp

Phần này dành cho những ai đã "hơi hơi" biết config Apache2.Nói mang đến debug ngẫu nhiên service làm sao của Linux, hãy nghĩ mang lại file log đầu tiên. Về cơ bản thì đọc hoàn thành log là bạn đã sở hữu thể xử lý vấn đề rồi (trừ số đông trường hợp siêu oái oăm). Nơi đặt log error chúng ta cũng có thể dễ dàng thấy trong file config trên, nó nghỉ ngơi /var/log/apache2/error.log Các lỗi thường gặp:403 Forbidden : thường bạn sẽ gặp lỗi này khi trong thư mục chúng ta vào không có file index.html giỏi index.php.Bạn hoàn toàn có thể thêm directive Options Indexesđể apache2 hiện nay danh sách các file trong thư mục đó thay thông báo 403.Nếu vấn đề là vì permission, bạn sẽ dễ dàng tìm thấy trong log :D...Và cuối cùng, hãy nhớ chmod 755 là an toàn, 777 là dại (trừ khi chúng ta biết bản thân không ngây ngô :D )hvn
lappy: /usr/lib/cgi-bin $ ls -lt
-rwxr-xr-x 1 root root 37 Dec 22 17:31 test.py đây là 755-rw-r--r-- 1 root root 0 Dec 22 17:27 index.cgi-rwxrwxrwx 1 root root 5 Dec 22 17:17 index.xxx đây là 777Hãy google và tự học config apache2, cũng ko loằng ngoằng lắm, hoặc nếu muốn ăn "sổi" thì nên học lệnh (directive) Alias để maps link đến những site khác nhau trên trang bị mình.Tắm rồi ăn thôi, không học được gì cả :((PS: nhằm luyện hiểu mã nhị phân / hexa với smartphone android của bạn, hãy cài áp dụng này vào :v https://play.google.com/store/apps/details?id=com.hvn.geekgame ghi nhớ +1 cùng 5 sao nhóe :x )

From Cold
Fusion 11, you can now use all the relevant Cold
Fusion tags within CFScript blocks. In the versions before Cold
Fusion 11, most of the Cold
Fusion tags were not available in the script syntax. If you are coding in script block and required to gọi a tag, you had no choice but to lớn come out of script block và use tag syntax.

With script support for CF tags added khổng lồ Cold
Fusion 11, you can now write all your code in a CFSCRIPT block itself.

Script tư vấn is available for both simple tags as well as nested tags. For instance, you can use a simple CFHTTP tag in a CFScript block (refer /script/http_simple.cfm), as follows:


You can also invoke a CFHTTP tag passing additional information through CFHTTPPARAM, making it a nested call, as shown below:


Cfhttp(URL=http://#CGI.SERVER_NAME#.../target.cfm, method=”GET”) cfhttpparam(type="https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpgurl"https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpg, name='emp_name' value=”Jacob”); cfhttpparam(type="https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpgheader"https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpg, name='myheader' value=”My custom header”); Writeoutput(cfhttp.filecontent);
As general syntax for script support, a Cold
Fusion tag is invoked lượt thích a function gọi in CFSCRIPT block with tag name is used for the function name. The tag attributes are passed as comma separated name-value pairs to lớn it, like arguments are passed to a function. The child tag (and the body in general) is defined within a curly brackets, just like a function block.


The script syntax is also extended khổng lồ invoke custom tags. You can invoke a custom tag in Cold
Fusion using two methods and both of them are supported for CFSCRIPT block. 

Cfm file based custom tags Prefix based custom tags
You can invoke prefix based custom tag invocation. You first import a taglib & define a prefix khổng lồ use custom tags under your taglib folder. A custom tag file validate
User.cfm is present under security
Tags folder. This custom tag is used with prefix “security”, as follows:


// Prefix based custom tags cfimport(taglib="https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpgsecurity
Tags"https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpg, prefix="https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpgsecurity"https://cachseo.com/cgi-content-type-header/imager_1_1176_700.jpg); security:validate
User(name=’John’);

*

*

Cold
Fusion CFML Reference


Language Navigation