<?xml version='1.0' encoding='EUC-KR' ?> <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd"> <?xml-stylesheet type="text/xsl" href="../style/manual.ko.xsl"?> <!-- English Revision: 105989:545841 (outdated) --> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manualpage metafile="cgi.xml.meta"> <parentdocument href="./">How-To / Tutorials</parentdocument> <title>����ġ ���丮��: CGI�� ����� ���� ������ ����</title> <section id="intro"> <title>�Ұ�</title> <related> <modulelist> <module>mod_alias</module> <module>mod_cgi</module> </modulelist> <directivelist> <directive module="mod_mime">AddHandler</directive> <directive module="core">Options</directive> <directive module="mod_alias">ScriptAlias</directive> </directivelist> </related> <p>CGI (Common Gateway Interface)�� �������� ���� CGI ���α� Ȥ�� CGI ��ũ��Ʈ��� �θ���, (�������� ������ �����) �ܺ� ���α��� ����ϴ� ����� �����Ѵ�. ������Ʈ���� ������ �������� ����� ���� ���ϰ� ������ ����̴�. �� ������ ����ġ �������� CGI�� �����ϴ� ����� �Ұ��ϰ�, CGI ���α��� �ۼ��غ���.</p> </section> <section id="configuring"> <title>CGI�� ����ϵ��� ����ġ �����ϱ�</title> <p>CGI ���α��� �ùٷ� �����Ϸ��� CGI ������ �����ϵ��� ����ġ�� �����ؾ� �Ѵ�. �����ϴ� ����� ����������.</p> <section id="scriptalias"> <title>ScriptAlias</title> <p><directive module="mod_alias">ScriptAlias</directive> ���þ ����ϸ� ����ġ�� Ư�� ���丮�� CGI ���α������� �д�. ����ġ�� �� ���丮�� �ִ� ��� ������ CGI ���α��̶�� �����Ͽ� Ŭ���̾�Ʈ�� �ڿ��� ��û�ϸ� �ڿ��� �����Ϸ��� �õ��Ѵ�.</p> <p><directive module="mod_alias">ScriptAlias</directive> ���þ�� ������ ���� ����Ѵ�.</p> <example> ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/ </example> <p>�� ������ ����ġ�� �⺻ ��ҿ� ��ġ�� ��� <code>httpd.conf</code> �������Ͽ� �ִ� �����̴�. <directive module="mod_alias">ScriptAlias</directive> ���þ�� <directive module="mod_alias">Alias</directive> ���þ�� ���� URL �պκ��� Ư�� ���丮�� �����Ѵ�. <directive>Alias</directive>�� <directive>ScriptAlias</directive>�� ���� <directive module="core">DocumentRoot</directive> ���丮 �ۿ� �ִ� ���丮�� ����Ѵ�. <directive>Alias</directive>�� <directive>ScriptAlias</directive>�� �������� <directive>ScriptAlias</directive>�� �߰��� URL �պκ����� �����ϴ� ��� ������ CGI ���α����� ����ϴ� ���̴�. ���� ���� ������ ����ġ���� <code>/cgi-bin/</code>���� �����ϴ� �ڿ��� ��û�ϸ� <code>/usr/local/apache2/cgi-bin/</code> ���丮���� ã�Ƽ� CGI ���α����� ó���϶�� �˸���.</p> <p>���� ���, URL <code>http://www.example.com/cgi-bin/test.pl</code>�� ��û�ϸ� ����ġ�� <code>/usr/local/apache2/cgi-bin/test.pl</code> ������ �����Ͽ� ����� ��ȯ�Ѵ�. ���� ������ �����ϰ� ���డ���ϸ� � ������ε� ����� �ؾ� �Ѵ�. ���� ������ ����ġ�� �������� ������.</p> </section> <section id="nonscriptalias"> <title>ScriptAlias ���丮 �ۿ� �ִ� CGI</title> <p>���� ���Ȼ� ���������� CGI ���α��� <directive module="mod_alias">ScriptAlias</directive>�� ���丮�� �����Ѵ�. ���� �����ڴ� ���� CGI ���α��� ����� �� �ִ��� ������ ������ �� �ִ�. ���� ������ ������ġ�� ���ߴٸ� �ƹ� ���丮������ CGI ���α��� �������� ���� ������ ����. ���� ���, <directive module="mod_userdir">UserDir</directive> ���þ ����Ͽ� ����ڰ� �ڽ��� Ȩ���丮�� ���������� ������ ��츦 ��������. ����ڰ� �ڽ��� CGI ���α��� ����ϰ� ������ <code>cgi-bin</code> ���丮�� ���ٱ����� ���ٸ�, �ٸ� �������� CGI ���α��� �����ϰ� ���� ���̴�.</p> <p>�ƹ� ���丮������ CGI ������ ����Ϸ��� �� ������ �ʿ��ϴ�. ����, <directive module="mod_mime">AddHandler</directive>�� <directive module="core">SetHandler</directive> ���þ ����Ͽ� <code>cgi-script</code> �ڵ鷯�� �۵��ؾ� �Ѵ�. �ι�°��, <directive module="core">Options</directive> ���þ <code>ExecCGI</code>�� �����ؾ� �Ѵ�.</p> </section> <section id="options"> <title>Options�� ����Ͽ� ���������� CGI ������ ����ϱ�</title> <p>������ �ּ������Ͽ� ���� <directive module="core">Options</directive> ���þ ����Ͽ� Ư�� ���丮���� CGI ������ ����� �� �ִ�.</p> <example> <Directory /usr/local/apache2/htdocs/somedir><br /> <indent> Options +ExecCGI<br /> </indent> </Directory> </example> <p>�� ���þ�� ����ġ�� CGI ������ ������ ����Ѵ�. � ������ CGI ���������� �������� �˷��� �Ѵ�. ���� <directive module="mod_mime">AddHandler</directive> ���þ�� �������� Ȯ���ڰ� <code>cgi</code>�� <code>pl</code>�� ������ ��� CGI ���α��̶�� �˸���.</p> <example> AddHandler cgi-script .cgi .pl </example> </section> <section id="htaccess"> <title>.htaccess ����</title> <p><a href="htaccess.html"><code>.htaccess</code> ���丮��</a>�� <code>httpd.conf</code>�� ���ٱ����� ���� ��쿡 CGI ���α��� ����� �� �ִ� ����� �˷��ش�.</p> </section> <section id="userdir"> <title>����� ���丮</title> <p>�Ʒ� ������ ����ϸ� ����� ���丮���� <code>.cgi</code>�� ������ ������ CGI ���α����� �����Ѵ�.</p> <example> <Directory /home/*/public_html><br/> <indent> Options +ExecCGI<br/> AddHandler cgi-script .cgi<br/> </indent> </Directory> </example> <p>������ ����ϸ� ����� ���丮�� <code>cgi-bin</code> �������丮�� �ִ� ��� ������ CGI ���α����� �ν��Ѵ�.</p> <example> <Directory /home/*/public_html/cgi-bin><br/> <indent> Options ExecCGI<br/> SetHandler cgi-script<br/> </indent> </Directory> </example> </section> </section> <section id="writing"> <title>CGI ���α� �ۼ��ϱ�</title> <p>``�Ϲ�����'' ���α��ְ� CGI ���α��� ���̿��� �ΰ��� �ֵ� �������� �ִ�.</p> <p>ù��° ���̴� CGI ���α��� �ٸ� ����� �ϱ����� ���� MIME-type ����� ����ؾ� �Ѵٴ� ���̴�. HTTP ����� Ŭ���̾�Ʈ���� Ŭ���̾�Ʈ�� � ������ �ްԵ��� �̸� �˸���. ���� ������ ����.</p> <example> Content-type: text/html </example> <p>�ι�° ���̴� HTML Ȥ�� �������� ������ �� �ִ� �������� ����ؾ� �Ѵٴ� ���̴�. ��κ��� ��� HTML�� ���������, ������ gif ���� ���� HTML�� �ƴ� ������ ����ϴ� CGI ���α��� �ۼ��ϴ� ��쵵 �ִ�.</p> <p>�ΰ����� �����ϰ��� CGI ���α� �ۼ��� �̹� ����� ������ �ٸ� ���α���� �ſ� ����ϴ�.</p> <section id="firstcgi"> <title>ó������ ���� CGI ���α�</title> <p>������ �������� �� ���� ��� CGI ���α� ������. �״�� <code>first.pl</code>�̶�� ���Ͽ� �����ϰ�, <code>cgi-bin</code> ���丮�� �����Ѵ�.</p> <example> #!/usr/bin/perl<br /> print "Content-type: text/html\n\n";<br /> print "Hello, World."; </example> <p>Perl�� �ͼ����� �ʴ��� ���� ���� �Ͼ���� �� �� �ִ�. ù��° ���� ����ġ(Ȥ�� ����ϴ� ��)���� <code>/usr/bin/perl</code> ��ġ�� �ִ� ������������ ����Ͽ� �� ���α� ������ �����϶�� �˸���. �ι�° ���� ��� ���� content-type ������ ����ϰ� carriage-return �ٹٲ��� �ι� ����Ѵ�. ���� ��� �ڿ� HTTP ����� ���� ���ϴ� ������ �����, ������ �����Ѵ�. ����° ���� "Hello, World." ���ڿ��� ����Ѵ�. �̰����� ���̴�.</p> <p>�������� �����ϰ� �ּҸ� �Է��Ѵ�</p> <example> http://www.example.com/cgi-bin/first.pl </example> <p>���� ��Ҹ� �Է��ϸ�, ������â�� <code>Hello, World.</code> �� ���� ���δ�. ��е����� ������, �ѹ� �����ϴ� ���� �������� ���� �ٸ� ���� �õ��� �� �� �ִ�.</p> </section> </section> <section id="troubleshoot"> <title>���� ���� �������� �ʾƿ�!</title> <p>������ CGI ���α��� �����Ҷ� �������� ���� �� �ִ� ������ �⺻������ �װ�����.</p> <dl> <dt>CGI ���α��� ���</dt> <dd>����! ��� ���� �� �����Ѵٴ� ���̴�. ����� ��Ȯ������ �������� �ùٷ� ó������ ���Ѵٸ�, CGI ���α����� �ùٸ� <code>Content-Type</code>�� �����Ͽ����� Ȯ���Ѵ�.</dd> <dt>CGI ���α� �ҽ��ڵ� Ȥ�� "POST Method Not Allowed" ����</dt> <dd>CGI ���α��� �����ϵ��� ����ġ�� ������ �������� �ʾҴٴ� ���̴�. <a href="#configuring">����ġ �����ϱ�</a> ���� �ٽ� �а� ������ �κ��� �ִ��� ã�ƺ���.</dd> <dt>"Forbidden"���� �����ϴ� ����</dt> <dd>���� ������ �ִٴ� ���̴�. <a href="#errorlogs">����ġ ���� �α�</a>�� �Ʒ� <a href="#permissions">���ϱ���</a> ���� Ȯ���϶�.</dd> <dt>"Internal Server Error"��� ����</dt> <dd><a href="#errorlogs">����ġ ���� �α�</a>�� ���� �Ƹ��� CGI ���α��� ����� �������� �Բ� "Premature end of script headers"�� ���� ���̴�. �� ��� �Ʒ� ������� �ϳ��� Ȯ���Ͽ� � ������ CGI ���α��� ������ HTTP ����� ������� ���ߴ��� �˾ƺ���.</dd> </dl> <section id="permissions"> <title>���ϱ���</title> <p>������ ��Ű� ������ �������� �������� ������ �����϶�. ��, ������ �����ϸ� ������ ��Ư�� ����� ����(���� <code>nobody</code>�� <code>www</code>)���� �����Ѵ�. ���� ����� ������ ������ �����Ϸ��� ������ �ʿ��ϴ�. ���Ͽ� <code>nobody</code>�� �����ϱ ����� ������ �ֱ����� ���� ��ο��� ������ ���� ������ �ش�.</p> <example> chmod a+x first.pl </example> <p>��, ���α��� �ٸ� ������ �аų� ���ٸ� �� ���Ͽ��� ������ ������ �ʿ��ϴ�.</p> </section> <section id="pathinformation"> <title>��� ������ ȯ��</title> <p>������� ���α��� �����ϸ� �ڵ����� � ������ ���� ���ȴ�. ���� ���, <code>PATH</code>�� ������ ����� ���� ������ ã�� ��Ҹ� �˷��ش�.</p> <p>�������� ���α��� CGI ���α����� �����Ҷ��� <code>PATH</code>�� �ٸ� �� �ִ�. (���� ���, <code>sendmail</code> ����) CGI ���α� �ȿ��� �����ϴ� ���ɾ�� ������ ��η� �����ؾ� ���� ���ɾ ã�� �� �ִ�.</p> <p>��� ������ ������ ���� CGI ���α� ù��° �ٿ� ������ ��ũ��Ʈ ���������� (���� <code>perl</code>) ��ο��� ���� ���Ѵ�.</p> <example> #!/usr/bin/perl </example> <p>������ ������������ ������� Ȯ���Ѵ�.</p> <p>��, CGI ���α��� �ٸ� <a href="#env">ȯ�溯��</a>�� ����Ѵٸ� ����ġ�� �� �������� ���α����� �����ؾ� �Ѵ�.</p> </section> <section id="syntaxerrors"> <title>���α� ����</title> <p>CGI ���α��� �����ϴ� ��� ��κ� ���α� ��ü ���������̴�. Ư�� ���� �ΰ��� �Ǽ��� ���� �ʾҰ� �� ���� ��� ���� �ִٸ� ������ ����. ���� ���������� �����ϱ� ���� ������� ���α��� �����غ���. ���� ���, ������ ���� �����Ѵ�.</p> <example> cd /usr/local/apache2/cgi-bin<br/> ./first.pl </example> <p>(<code>perl</code> ���������� �������� ����. ���� ����ġ�� ��ũ��Ʈ ù��° �ٿ� �ִ� <a href="#pathinformation">��� ����</a>�� ����Ͽ� ���������� ã�ƾ� �Ѵ�.)</p> <p>���α��� ���� ���� <code>Content-Type</code>�� ������ HTTP ������� ����ϰ� �� ���� ����ؾ� �Ѵ�. �ٸ� ���� ����Ѵٸ� ���������� ������ ��� ����ġ�� <code>Premature end of script headers</code>�� ��ȯ�Ѵ�. �ڼ��� ������ ���� <a href="#writing">CGI ���α� �ۼ��ϱ�</a>�� �����϶�.</p> </section> <section id="errorlogs"> <title>���� �α�</title> <p>���� �α״� ��� ���̴�. ���� �߸��Ǹ� ���� �α� ������ �����. ���� �α� ���� ���� ������� �Ѵ�. ������Ʈ�� ȣ�����ϴ� ������ ���� �α� ���� ���ϰ� �Ѵٸ�, �Ƹ��� �ٸ� ��ü�� �˾ƺ��� �Ѵ�. ���� �α� ���� ����� ������, ��κ��� ������ ���� �ľ��Ͽ� �ذ��� �� �ִ�.</p> </section> <section id="suexec"> <title>Suexec</title> <p><a href="../suexec.html">suexec</a> ���� ���α��� ����ϸ� � ����ȣ��Ʈ Ȥ�� � ����� ���丮�� �ִ����� ���� CGI ���α��� �ٸ� ����� �������� ������ �� �ִ�. Suexec�� �ſ� �����ϰ� ������ �˻��ϸ�, �˻縦 �ϳ��� ������� ���ϸ� CGI ���α��� �������� �ʰ� <code>Premature end of script headers</code>�� ��ȯ�Ѵ�.</p> <p>suexec�� ����ϰ� �ִ��� �˷��� <code>apachectl -V</code>�� �����Ͽ� <code>SUEXEC_BIN</code> ��ġ�� Ȯ���Ѵ�. ����ġ�� �����Ҷ� �� ��ҿ��� suexec ���������� �߰��ϸ�, suexec�� ����� �� �ִ�.</p> <p>suexec�� ������ �������� ���ߴٸ� ����ؼ��� �ȵȴ�. suexec�� ������� �������� <code>SUEXEC_BIN</code> ��ġ�� �ִ� <code>suexec</code> ���������� ����� (Ȥ�� ���ϸ��� �ٲٰ�) ������ ������ϸ� �ȴ�. <a href="../suexec.html">suexec</a>�� ���� ���� ���� ���� ����ϰ� �ʹٸ�, <code>suexec -V</code>�� �����Ͽ� suexec �α����� ��ġ�� �˾Ƴ��� �α����Ͽ��� ����� � ��Ģ�� ���� �ִ��� ã�´�.</p> </section> </section> <section id="behindscenes"> <title>�ڿ����� ���� ���� �������°�?</title> <p>CGI ���α��ֿ� �ͼ��������� �ڿ��� �������� ���� �����ϸ� ������ �ȴ�. ��ü������ �������� ������ ���� ����ϴ� ����� ���ϴ� ���̴�. ���� "Hello, World."�� ����ϴ� ���α��� �ۼ��� �� ������ �̷� ���α��� ���� ���� ������̴�.</p> <section id="env"> <title>ȯ�溯��</title> <p>ȯ�溯���� ����� ��ǻ�� ����ϴ� ���� ��� ������ ���ٴϴ� ���̴�. ȯ�溯���� path (��ǻ�Ͱ� ����� �Է��� ���ɾ �ش��ϴ� ���� ������ ã�� ���), ����ڸ�, �̳� ������ ���� ������ ������. �Ϲ����� ȯ�溯���� ��� ������ ������ ������Ʈ���� <code>env</code>�� �Է��Ѵ�.</p> <p>CGI�� �����Ҷ��� ������ �������� ������ ȯ�溯���� ���� ��ȯ�Ѵ�. �� �������� ������ ���� (Netscape, IE, Lynx), ���� ���� (����ġ, IIS, WebSite), �����ϴ� CGI ���α��� ���� �ִ�.</p> <p>CGI ���α��Ӵ� �̷� �������� ����� �� �ְ�, ȯ�溯���� Ŭ���̾�Ʈ-���� ��ſ��� �Ϻκ��� �����Ѵ�. ��ü �ʼ� ���� ����� <a href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html" >http://hoohoo.ncsa.uiuc.edu/cgi/env.html</a>�� �ִ�.</p> <p>�Ʒ� ������ Perl CGI ���α��� �ڽſ��� ���� ��� ȯ�溯���� �����ش�. ����ġ �������� <code>cgi-bin</code> ���丮�� �̿� ����� ���α��� �ΰ� �ִ�. ��� ������ �ʼ��̰� �������� �������̴�. ���� ���� ��Ͽ� ���� ������ ���δ�. ��, ����ġ�� �⺻������ �����ϴ� ȯ�溯�� �ܿ� �������� ������� <a href="../env.html">���� ȯ�溯���� �߰��� �� �ִ�</a>.</p> <example> #!/usr/bin/perl<br /> print "Content-type: text/html\n\n";<br /> foreach $key (keys %ENV) {<br /> <indent> print "$key --> $ENV{$key}<br>";<br /> </indent> } </example> </section> <section id="stdin"> <title>STDIN�� STDOUT</title> <p>��, ������ Ŭ���̾�Ʈ�� ǥ���Է�(<code>STDIN</code>)�� ǥ�����(<code>STDOUT</code>)���� ����Ѵ�. �ϻ����� ��� <code>STDIN</code>�� Ű���峪 ���α��� ó���ϴ� ������ ��Ÿ����, <code>STDOUT</code>�� ���� �ܼ��̳� ȭ���� ���Ѵ�.</p> <p>CGI ���α����� �� ���(form)�� <code>POST</code>�ϸ� ��Ŀ� �Է��� �ڷḦ Ư���� �������� ��� CGI ���α��� <code>STDIN</code>���� �����Ѵ�. ���� ���α��� Ű���峪 ���Ͽ��� ���� �ڷḦ ó���ϵ��� �ڷḦ ó���� �� �ִ�.</p> <p>"Ư���� ����"�� �ſ� �����ϴ�. �� �̸��� ���� ��ȣ(=)�� �����ϰ�, �� �̸��� ���� �ֵ��� ���� ���ۻ���(&)�� �����Ѵ�. ����, ���ۻ���, ��ȣ ���� ���ڿ������� ���ڴ� ȥ������ �ʵ��� 16������ ��ȯ�Ѵ�. ������ �ڷ� ���ڿ��� ������ ���� �����.</p> <example> name=Rich%20Bowen&city=Lexington&state=KY&sidekick=Squirrel%20Monkey </example> <p>���� URL �ڿ��� �̷� ���ڿ��� ���� �ȴ�. �� ��� ������ ���ڿ��� <code>QUERY_STRING</code>�̶�� ȯ�溯���� �����Ѵ�. �̸� <code>GET</code> ��û�̶�� �Ѵ�. <code>FORM</code> �±��� <code>METHOD</code> �Ӽ��� �����Ͽ� HTML ���(form)�� �ڷḦ <code>GET</code>���� <code>POST</code>���� �����Ѵ�.</p> <p>���� ���α��� �̷� ���ڿ��� ������ ������ �ɰ��� �Ѵ�. �������� �̷� �ڷ� ó���� ���� CGI ���α��� �ٸ� ���� ���� ���Ǵ� ���̺귯���� ������ �ִ�.</p> </section> </section> <section id="libraries"> <title>CGI ���/���̺귯��</title> <p>CGI ���α��� �ۼ��Ҷ� ������ �۾��� ������ִ� �ڵ� ���̺귯�� Ȥ�� ����� ������� �����غ��� �Ѵ�. �̷� ���� ����ϸ� ���װ� �ٰ� �� ���� ���α��� ������ �� �ִ�.</p> <p>Perl�� CGI ���α��� �ۼ��Ѵٸ� <a href="http://www.cpan.org/">CPAN</a>���� ���� ������ ã�� �� �ִ�. CGI ���߿� ���� �θ� ���Ǵ� ����� <code>CGI.pm</code>�̴�. ��κ��� ���α��� ����� �ּ� ����� ������ <code>CGI::Lite</code>�� ������ �� �� �ִ�.</p> <p>C�� CGI ���α��� �ۼ��Ѵٸ� ������ ������ ����. ���� �ϳ��� <a href="http://www.boutell.com/cgic/">http://www.boutell.com/cgic/</a>�� �ִ� <code>CGIC</code> ���̺귯����.</p> </section> <section id="moreinfo"> <title>�� ���� ����...</title> <p>���� �ſ� ���� CGI ������ �ִ�. ������ <a href="news:comp.infosystems.www.authoring.cgi" >comp.infosystems.www.authoring.cgi</a>���� ���� ������ CGI ������ ������ �� �ִ�. HTML Writers Guild�� -servers ���ϸ�����Ʈ�� ������ ���� ���� ã� �Ǹ��� ��Ҵ�. <a href="http://www.hwg.org/lists/hwg-servers/" >http://www.hwg.org/lists/hwg-servers/</a>���� �� ���� ���� �� �� �ִ�.</p> <p>���� ���� CGI ���α� ���ۿ� ���� ��� ������ ������ CGI �Ծ��� �о�� ������ ��. <a href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html">NCSA</a>�� ���� ������ �ְ�, ������ �ʾ��� <a href="http://web.golux.com/coar/cgi/">Common Gateway Interface RFC ������Ʈ</a>�� �ִ�.</p> <p>���ϸ�����Ʈ�� �����쿡 ���� �ݰ� �ִ� CGI ������ ���� �����Ҷ��� ���� ����� ���� ����� ���, ������ ���� ������ ��� �ٸ���, ����ϴ� ����, CGI ���α��� �ۼ��� ���, �����ϸ� �ش� �ڵ带 �ڼ��� �����. ���� �ذ�å�� ã�� ��������.</p> <p>����ġ �ҽ��ڵ尡 �߸��Ǿ��ٰ� Ȯ������ �ʴ� �� CGI ������ ����ġ ���� �����ͺ��̽��� �ø��� <strong>�����</strong> �ȵȴ�.</p> </section> </manualpage>