Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách cấu hình Apache cho Python CGI Programming?

Cấu hình Apache Web Server cho CGI

Để server chạy CGI script đúng cách, cần cấu hình web server. Thảo luận cách cấu hình Apache chạy CGI scripts.

Sử dụng ScriptAlias

Đặt một thư mục làm ScriptAlias Directive. Apache hiểu tất cả file trong thư mục đó là CGI scripts. Cách đơn giản nhất. Dòng ScriptAlias điển hình trong httpd.conf:

ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/

Tìm ScriptAlias trong httpd.conf và uncomment (bỏ #) nếu muốn giữ CGI ở thư mục mặc định.

Chạy CGI từ thư mục cụ thể (khác mặc định)

<Directory /usr/local/apache2/htdocs/somedir>
Options +ExecCGI
</Directory>

Cần thêm để chỉ định extension file CGI:

AddHandler cgi-script .cgi .pl

User Directories

Chạy CGI từ thư mục user:

<Directory /home/*/public_html>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

Chạy tất cả file trong thư mục user làm CGI:

<Directory /home/*/public_html/cgi-bin>
Options +ExecCGI
SetHandler cgi-script
</Directory>

Sử dụng .htaccess

Nếu không truy cập httpd.conf, dùng .htaccess:

Options +ExecCGI
AddHandler cgi-script cgi pl

Chạy tất cả file trong thư mục làm CGI:

Options +ExecCGI
SetHandler cgi-script