Nginx AWS auth on Ubuntu 10.04
S3ã«ä¿åããããã¡ã¤ã«ãç´æ¥S3ã«ã¢ã¯ã»ã¹ãããããªãå ´åã®Nginxã®è¨å®ã§ãã
é常ã¯ãç´ ç´ã«ã¯ã©ã¦ãããã³ããå©ç¨ããã°ãããããªæ°ããã¾ããã調ã¹ã¦ã¿ãã®ã§ã¡ã¢ãã¦ããã¾ãã
Nginxããèªè¨¼ä»ãã§S3ã«ã¢ã¯ã»ã¹ããã«ã¯ãµã¼ããã¼ãã£ã®ã¢ã¸ã¥ã¼ã«AWS Authãå©ç¨ãã¾ãã
ã¢ã¸ã¥ã¼ã«ã¯ä»¥ä¸ã®ãªã³ã¯ãããã¦ã³ãã¼ãã§ãã¾ãã
http://wiki.nginx.org/3rdPartyModulesJa
ã¤ã³ã¹ãã¼ã«
ã¢ã¸ã¥ã¼ã«ã追å ãã¦Nginxãã³ã³ãã¤ã«ããããã«å¿
è¦ãª
unzipã¨gccãå«ãbuild-essentialããããããã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
$ sudo apt-get update
2012.11.03ç¾å¨ã§ã¯ãapt-get updateãã¦ãããªãã¨ãªãã¸ããªã®ãã¹ãå¤ãã£ã¦ãã¦gccã®ã¤ã³ã¹ãã¼ã«ã«å¤±æãã¾ã
$ sudo apt-get install unzip gcc build-essential $ sudo apt-get install libpcre3 libpcre3-dev $ sudo apt-get install zlib1g-dev $ sudo apt-get install openssl libssl-dev
Nginxã®ã½ã¼ã¹ããã¦ã³ãã¼ããã¦è§£åãã¦ããã¾ãã
$ wget http://nginx.org/download/nginx-1.2.4.tar.gz $ tar xvfz nginx-1.2.4.tar.gz $ cd nginx-1.2.4
次ã«AWS Authã¢ã¸ã¥ã¼ã«ããã¦ã³ãã¼ããã¾ãã
$ wget https://github.com/anomalizer/ngx_aws_auth/zipball/master $ mv master aws-auth.zip $ unzip aws-auth.zip
configureãã¦make
$./configure --sbin-path=/usr/sbin \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --with-debug \ --with-http_stub_status_module \ --with-http_flv_module \ --with-http_ssl_module \ --with-http_dav_module \ --with-http_gzip_static_module \ --with-http_realip_module \ --with-mail \ --with-mail_ssl_module \ --with-ipv6 \ --add-module=./anomalizer-ngx_aws_auth-37adfc3 ... configuring additional modules adding module in ./anomalizer-ngx_aws_auth-37adfc3/ + ngx_http_aws_auth was configured checking for PCRE library ... found checking for PCRE JIT support ... not found checking for system md library ... not found checking for system md5 library ... not found checking for OpenSSL md5 crypto library ... not found checking for sha1 in system md library ... not found checking for OpenSSL sha1 crypto library ... not found checking for zlib library ... found creating objs/Makefile Configuration summary + using system PCRE library + using system OpenSSL library + md5: using OpenSSL library + sha1: using OpenSSL library + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/sbin" nginx configuration prefix: "/etc/nginx" nginx configuration file: "/etc/nginx/nginx.conf" nginx pid file: "/var/run/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/lib/nginx/body" nginx http proxy temporary files: "/var/lib/nginx/proxy" nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" $ make ... objs/src/http/modules/ngx_http_browser_module.o \ objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \ objs/src/http/modules/ngx_http_upstream_least_conn_module.o \ objs/src/http/modules/ngx_http_upstream_keepalive_module.o \ objs/addon/anomalizer-ngx_aws_auth-37adfc3/ngx_http_aws_auth.o \ objs/ngx_modules.o \ -lpthread -lcrypt -lssl -lpcre -lcrypto -lcrypto -lz make[1]: Leaving directory `/home/hrendoh/nginx-1.2.2' make -f objs/Makefile manpage make[1]: Entering directory `/home/hrendoh/nginx-1.2.2' sed -e "s|%%PREFIX%%|/usr/local/nginx|" \ -e "s|%%PID_PATH%%|/var/run/nginx.pid|" \ -e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \ < man/nginx.8 > objs/nginx.8 make[1]: Leaving directory `/home/hrendoh/nginx-1.2.2' ...
ã¤ã³ã¹ãã¼ã«
$ sudo make install
è¨å®
ãããªæãã§ã
location /s/attachment/ { proxy_pass http://<ãã±ããå>.s3.amazonaws.com/; aws_access_key xxxxxxxxxxxxxxxx; aws_secret_key xxxxxxxxxxxxxxxx s3_bucket <ãã±ããå>; chop_prefix /s/attachment; proxy_set_header Authorization $s3_auth_token; proxy_set_header x-amz-date $aws_date; }