![cgiを有効にする](https://i0.wp.com/cgishop.net/wp-content/uploads/2021/10/cgiを有効にする.png?resize=1080%2C1080&ssl=1)
cgiを有効にする
2021年10月7日
CGI を有効にする方法
CGI を有効にする方法は、Web サーバーの種類や環境によって異なります。以下では、一般的な Web サーバーである Apache と Nginx の場合について説明します。
Apache
Apache で CGI を有効にするには、以下の手順を実行します。
- httpd.conf ファイルを編集します。 このファイルは通常、
/etc/httpd/conf/
ディレクトリにあります。 - 以下の行を
httpd.conf
ファイルに追加します。
AddHandler cgi-script .cgi .pl .py
- 以下の行を
httpd.conf
ファイルに追加します。
Options ExecCGI
- 以下の行を
httpd.conf
ファイルに追加します。
Directory /path/to/cgi-scripts
AllowOverride None
Options ExecCGI
Require all granted
</Directory>
上記の例では、/path/to/cgi-scripts
ディレクトリ内のすべての .cgi、.pl、および .py ファイルが CGI スクリプトとして実行されます。
- Apache を再起動します。
sudo service apache2 restart
Nginx
Nginx で CGI を有効にするには、以下の手順を実行します。
- nginx.conf ファイルを編集します。 このファイルは通常、
/etc/nginx/nginx.conf
ディレクトリにあります。 - 以下の行を
nginx.conf
ファイルに追加します。
location ~ \.(cgi|pl|py)$ {
root /path/to/cgi-scripts;
index index.cgi index.pl index.py;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
上記の例では、/path/to/cgi-scripts
ディレクトリ内のすべての .cgi、.pl、および .py ファイルが CGI スクリプトとして実行されます。
- Nginx を再起動します。
sudo service nginx restart
その他の注意事項
- CGI スクリプトは、Web サーバーが実行されているユーザーと同じユーザー権限で実行されます。そのため、CGI スクリプトに適切な権限を付与する必要があります。
- CGI スクリプトは、セキュリティ上の脆弱性を含む可能性があります。そのため、CGI スクリプトを慎重にコーディングし、最新の状態を維持することが重要です。
参考情報
- Apache CGI ドキュメント: https://httpd.apache.org/docs/2.4/howto/cgi.html
- Nginx CGI ドキュメント: https://stackoverflow.com/questions/11667489/how-to-run-cgi-scripts-on-nginx
何か質問があれば、遠慮なく聞いてください。
Last Updated on 2024年7月5日10:37 am by cgishop