Nginx proxy everything under a path to a specific file on a remote server -


i have rails running @ example.com behind nginx. example.com/foobar hit rails app path /foobar, , good.

what want add example.com/spa/* loads specific file remote server (in case s3 bucket, that's not important).

so, i'd want nginx map things so:

example.com/ -> rails app path / example.com/foo -> rails app path /foo example.com/bar?what=ever -> rails app path /bar?what=ever  example.com/spa -> my-bucket.amazonaws.com/index.html example.com/spa/foo -> my-bucket.amazonaws.com/index.html example.com/spa/bar?what=ever -> my-bucket.amazonaws.com/index.html 

the first 3 examples easy- that's just

location / {   proxy_redirect off;   proxy_pass http://app_server; } 

(with upstream app_server defined elsewhere)

the second 3 example, though, i'm not sure how do.

tldr: how proxy under specific path single file/path on remote server?

use:

location ^~ /spa {     rewrite ^ /index.html break;     proxy_pass ...; } 

the ^~ modifier may not necessary, unless have regular expression locations @ same level. causes prefix location take precedence. see this document details.

the rewrite ... break causes modified uri processed within current location block. see this document details.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -