Created
July 8, 2012 17:40
-
-
Save geta6/3071997 to your computer and use it in GitHub Desktop.
nginxで静的コンテンツとphpとnodejsのリクエストをうまいことさばく
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream proxy { | |
server localhost:3000; | |
} | |
server { | |
listen 80 default_server; | |
server_name _; | |
return 404; | |
} | |
server { | |
listen 80; | |
charset UTF-8; | |
server_name geta6.com | |
favorymous.com | |
permsproject.com; | |
rewrite ^ http://www.$host; | |
} | |
server { | |
listen 80; | |
charset UTF-8; | |
server_name ~^(.+)\.(geta6\.com)$ | |
~^(.+)\.(favorymous\.com)$ | |
~^(.+)\.(permsproject\.com)$; | |
set $subdomain $1; | |
set $hostbase $2; | |
root /var/www/$hostbase/$subdomain/public; | |
location / { | |
index index.php index.html; | |
if (-f $request_filename) { | |
expires 7d; | |
break; | |
} | |
if (-f $request_filename/index.php) { | |
rewrite ^(.*) $uri/index.php last; | |
break; | |
} | |
if (-f $document_root/index.php) { | |
rewrite ^(.*) /index.php last; | |
break; | |
} | |
if (!-f $request_filename) { | |
proxy_pass http://proxy; | |
} | |
location ~* \.php$ { | |
fastcgi_pass localhost:9000; | |
include /etc/nginx/conf.d/fastcgi.conf | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
proxy = require 'http-proxy' | |
proxy.createServer( (req, res, proxy) -> | |
switch req.headers.host | |
when 'www.favorymous.com' then port = 30001 | |
else port = 404 | |
proxy.proxyRequest req, res, | |
host: req.headers.host | |
port: port | |
).listen 3000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment