It is indeed possible. Try one of the two options provided below...
server {
listen 80;
server_name
myapp.*
root /srv/myapp/current/public;
location /blog {
# option 1
return 444;
# option 2
# rewrite /blog/(.*) $scheme://blog.myapp.tld/$1 permanent;
}
}
server {
listen 80;
server_name
blog.myapp.*
root /srv/myapp/current/public/blog;
}
Some explanation on the two options...
return 444
is a Nginx specific status code, returning nothing to the browser. Ref: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes . If you prefer to send another status code, for example 403, then remove 444 and put whatever the code you prefer;
rewrite /blog/(.*) $scheme://blog.myapp.tld/$1 permanent;
converts the sub-directory to sub-domain. This has been already answered. Ref: Nginx rewrite rule (subdirectory to subdomain)
You may know more about the return
statement at http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return and about the rewrite
statement at http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite .
I hope that helps.