Nginx – autoindex css

Nginx 에서 autoindex 옵션이 on으로 설정되어 있는 경우 index 페이지가 없으면 아래 그림처럼 보여줍니다.
아파치에서는 autoindex 로 설정이 가능하지만 Nginx 에서는 설정이 불가능한걸로 보이길래.. 구글링하다 외국 블로그에서 패치 방법을 찾았습니다.

Nginx 소스 디렉토리의 ngx_http_autoindex_module.c 소스에 3가지 static u_char title, static u_char header, static u_char tail 부분을 적절하게 수정하고 컴파일 하면 됩니다.

패치 적용

[root@yongbok ~]# cd /usr/local/src
[root@yongbok ~]# wget http://nginx.org/download/nginx-1.2.7.tar.gz
[root@yongbok ~]# tar xzvf nginx-1.2.7.tar.gz
[root@yongbok ~]# cd nginx-1.2.7
[root@yongbok ~]# wget http://mirror.yongbok.net/ruo91/nginx/patch/ngx_http_autoindex_module.c.patch
[root@yongbok ~]# patch -p0 < ngx_http_autoindex_module.c.patch
Hmm… Looks like a unified diff to me…
The text leading up to this was:
————————–
|— src/http/modules/ngx_http_autoindex_module.c 2010-05-24 21:35:10.000000000 +0900
|+++ src/http/modules/ngx_http_autoindex_module.c.orig 2010-09-22 16:03:39.000000000 +0900

 

컴파일 ( 의존성 걸리는건 알아서 설치 해주시길.. -.-; )

[root@yongbok ~]# touch install.sh
[root@yongbok ~]# chmod +x install.sh
[root@yongbok ~]# vi install.sh
#!/bin/sh
uname=uname -s
OS_1=”FreeBSD”
OS_2=”Linux”

# FreeBSD
if [ "$uname" = "$OS_1" ]; then
prefix=/usr/local/nginx
tmp=/usr/local/nginx/tmp
./configure –prefix=$prefix \
–error-log-path=$prefix/log \
–pid-path=$tmp \
–lock-path=$tmp \
–user=www \
–group=www \
–with-http_image_filter_module \
–with-http_geoip_module \
–with-http_sub_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_gzip_static_module \
–with-http_random_index_module \
–with-http_secure_link_module \
–with-http_degradation_module \
–with-http_stub_status_module \
–with-rtsig_module \
–without-select_module \
–without-poll_module \
–with-file-aio \
–with-ipv6 \
–with-http_ssl_module \
–with-http_realip_module \
–with-http_addition_module \
–with-http_perl_module \
–http-log-path=$prefix/log \
–http-client-body-temp-path=$tmp/client \
–http-proxy-temp-path=$tmp/proxy \
–http-fastcgi-temp-path=$tmp/fastcgi \
–http-uwsgi-temp-path=$tmp/uwsgi \
–http-scgi-temp-path=$tmp/scgi \
–with-cpp_test_module \
–with-cpu-opt=pentium4 \
–with-pcre \
–with-md5-asm \
–with-sha1-asm \
–with-zlib-asm=pentium4 \
–with-perl=/usr/bin/perl

# Linux
elif [ "$uname" = "$OS_2" ]; then
prefix=/usr/local/nginx
tmp=/usr/local/nginx/tmp
./configure –prefix=$prefix \
–error-log-path=$prefix/log \
–pid-path=$tmp \
–lock-path=$tmp \
–user=nobody \
–group=nobody \
–with-http_image_filter_module \
–with-http_geoip_module \
–with-http_sub_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_gzip_static_module \
–with-http_random_index_module \
–with-http_secure_link_module \
–with-http_degradation_module \
–with-http_stub_status_module \
–with-rtsig_module \
–without-select_module \
–without-poll_module \
–with-file-aio \
–with-ipv6 \
–with-http_ssl_module \
–with-http_realip_module \
–with-http_addition_module \
–with-http_perl_module \
–http-log-path=$prefix/log \
–http-client-body-temp-path=$tmp/client \
–http-proxy-temp-path=$tmp/proxy \
–http-fastcgi-temp-path=$tmp/fastcgi \
–http-uwsgi-temp-path=$tmp/uwsgi \
–http-scgi-temp-path=$tmp/scgi \
–with-cpp_test_module \
–with-cpu-opt=pentium4 \
–with-pcre \
–with-md5-asm \
–with-sha1-asm \
–with-zlib-asm=pentium4 \
–with-perl=/usr/bin/perl

else
echo “Does not support.”
fi
[root@yongbok ~]# ./install.sh

 

가상 호스팅 설정

server {
listen 80;
server_name ftp.yongbok.net;
access_log log/mirror/ftp-access.log;
error_log log/mirror/ftp-error.log;

root /home2/ftp;
index index.html index.htm index.shtml index.php;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}

 

Nginx 시작

[root@yongbok ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/nginx.conf

실제로 페이지를 확인 해보면 패치한 내용대로 적용 되어 있는걸 볼수 있습니다. :D

참고
http://www.52crack.com/blog/?action=show&id=420

Loading Disqus Comments ...
Loading Facebook Comments ...

No Trackbacks.