Web
Apache2 cgi 동적 페이지
Tribal
2017. 4. 5. 02:28
cgi 실행을 위한 설정
$ vim /etc/apache2/apache2.conf ......... ScriptAlias /cgi-bin/ /var/www/html/cgi/cgi-bin/ <Directory /var/www/html/cgi/cgi-bin> Options +ExecCGI AddHandler cgi-script .cgi </Directory> $ a2enmod cgi $ service apache2 restart | cs |
- apache 설정 파일인 /etc/apache2/apache2.conf에 아래의 내용 추가
- CGI 파일을 실행하는 옵션과 스크립트 파일은 .cgi 파일이라고 정의해줌
- a2enmod cgi (이것때문에 안 된다고 얼마나 삽질을 했는지.... 후...)
- apache2 서비스 재시작
- 추가 : 검색해보면 여러 다양한 설정파일을 건드리는데 그냥 그 중 하나면 되는거 같다. 어차피 전부 설정 파일이니...
Test CGI 프로그램 소스코드(C언어)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdlib.h> #include <stdio.h> int main(void) { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<head>\n"); printf("<title>CGI Testing...</title>\n"); printf("</head>\n"); printf("<body>\n"); printf("<h1><b>hello</b></h1><br><br>Your IP Address is %s\n", getenv("REMOTE_ADDR")); printf("<br><br>QUERY_STRING is %s\n", getenv("QUERY_STRING")); printf("</body>\n"); printf("</html>\n"); return 0; } | cs |
Test 결과
GET 방식처럼 뒤에 넣어주는 인자 자체가 전부 QUERY_STRING 환경변수로 넘어가 전달된다. 그래서 AAAAA를 넣었더니 그대로 출력되는걸 볼 수 있음
기타 참고용
- http://httpd.apache.org/docs/2.2/ko/howto/cgi.html
- http://darphin.tistory.com/39 (C로 해서 그런지 딱히 뭔가 설치하지 않아도 상관없었다.)
- http://hodol.kr/xe/note/3656
이제 좀 더 재밌는 것을 하러...