Skip to content

Instantly share code, notes, and snippets.

@takp
Last active February 5, 2016 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takp/2593213e69cef6fc4efa to your computer and use it in GitHub Desktop.
Save takp/2593213e69cef6fc4efa to your computer and use it in GitHub Desktop.
Nginxでブラウザ言語判定してリダイレクトさせる方法 ref: http://qiita.com/tak_nishida/items/cc5ad5cb80a00d997b48
$ wget http://nginx.org/download/nginx-1.9.10.tar.gz
$ tar xvf nginx-1.9.10.tar.gz
$ git clone https://github.com/giom/nginx_accept_language_module.git
server {
...
set_from_accept_language $lang en ja;
rewrite ^(.*)$ $scheme://$lang.example.com$1;
...
}
server {
...
add_header debug_var $lang;
...
}
$ cd /usr/local/src
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
$ wget http://zlib.net/zlib-1.2.8.tar.gz
$ wget https://www.openssl.org/source/openssl-1.0.1r.tar.gz
$ tar xvf pcre-8.38.tar.gz
$ tar xvf zlib-1.2.8.tar.gz
$ tar xvf openssl-1.0.1r.tar.gz
./configure: error: the HTTP rewrite module requires the PCRE library.
$ ./configure \
--add-module=/usr/local/src/nginx_accept_language_module \
--with-pcre=/usr/local/src/pcre-8.38 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1r \
--with-http_ssl_module
$ make
$ sudo make install
$ nginx -v
nginx version: nginx/1.9.10
$ cd /etc/init.d
$ sudo vim nginx
nginx="/usr/local/nginx/sbin/nginx"
...
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
$ sudo service nginx start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment