Skip to main content
Tweeted twitter.com/ServerFault/status/1124464251291209728
deleted 12 characters in body
Source Link
tompave
  • 684
  • 3
  • 7
  • 15

In my nginx 1.12.2 conf file, I have:

upstream app { server unix:/tmp/app.sock fail_timeout=0; } server { listen 443 deferred; root /some/dir; try_files $uri @app; # If the request is for the naked domain, just serve the index bundle # without going through Rails # location = / { try_files /index.html =404; } # If the request if for the /api prefix, go directly to Rails. # This location block is not strictly required, but it could be a handy # customization hook for extra headers and settings. # location /api/ { # Extra conf! proxy_passtry_files @rails_app;@app; } # The location directory allows very creative configurations. # http://nginx.org/en/docs/http/ngx_http_core_module.html#location # # This is just a named location to be used in try_files. location @app { proxy_pass_request_headers on; proxy_set_header ... proxy_pass http://app; } } 

There, this is not really right because it has a single argument:

 location /api/ { # Extra conf! proxy_passtry_files @rails_app;@app; } 

...but it communicates well what I'm trying to achieve. I suppose I could get try_files to work by adding a non-esitent file before the last argument.

Is try_files the only way to do it, or is there another more idiomatic directive?

In my nginx 1.12.2 conf file, I have:

upstream app { server unix:/tmp/app.sock fail_timeout=0; } server { listen 443 deferred; root /some/dir; try_files $uri @app; # If the request is for the naked domain, just serve the index bundle # without going through Rails # location = / { try_files /index.html =404; } # If the request if for the /api prefix, go directly to Rails. # This location block is not strictly required, but it could be a handy # customization hook for extra headers and settings. # location /api/ { # Extra conf! proxy_pass @rails_app; } # The location directory allows very creative configurations. # http://nginx.org/en/docs/http/ngx_http_core_module.html#location # # This is just a named location to be used in try_files. location @app { proxy_pass_request_headers on; proxy_set_header ... proxy_pass http://app; } } 

There, this is not really right because it has a single argument:

 location /api/ { # Extra conf! proxy_pass @rails_app; } 

...but it communicates well what I'm trying to achieve. I suppose I could get try_files to work by adding a non-esitent file before the last argument.

Is try_files the only way to do it, or is there another more idiomatic directive?

In my nginx 1.12.2 conf file, I have:

upstream app { server unix:/tmp/app.sock fail_timeout=0; } server { listen 443 deferred; root /some/dir; try_files $uri @app; # If the request is for the naked domain, just serve the index bundle # without going through Rails # location = / { try_files /index.html =404; } # If the request if for the /api prefix, go directly to Rails. # This location block is not strictly required, but it could be a handy # customization hook for extra headers and settings. # location /api/ { # Extra conf! try_files @app; } # The location directory allows very creative configurations. # http://nginx.org/en/docs/http/ngx_http_core_module.html#location # # This is just a named location to be used in try_files. location @app { proxy_pass_request_headers on; proxy_set_header ... proxy_pass http://app; } } 

There, this is not really right because it has a single argument:

 location /api/ { # Extra conf! try_files @app; } 

...but it communicates well what I'm trying to achieve. I suppose I could get try_files to work by adding a non-esitent file before the last argument.

Is try_files the only way to do it, or is there another more idiomatic directive?

Source Link
tompave
  • 684
  • 3
  • 7
  • 15

nginx: directly send from location to another named location

In my nginx 1.12.2 conf file, I have:

upstream app { server unix:/tmp/app.sock fail_timeout=0; } server { listen 443 deferred; root /some/dir; try_files $uri @app; # If the request is for the naked domain, just serve the index bundle # without going through Rails # location = / { try_files /index.html =404; } # If the request if for the /api prefix, go directly to Rails. # This location block is not strictly required, but it could be a handy # customization hook for extra headers and settings. # location /api/ { # Extra conf! proxy_pass @rails_app; } # The location directory allows very creative configurations. # http://nginx.org/en/docs/http/ngx_http_core_module.html#location # # This is just a named location to be used in try_files. location @app { proxy_pass_request_headers on; proxy_set_header ... proxy_pass http://app; } } 

There, this is not really right because it has a single argument:

 location /api/ { # Extra conf! proxy_pass @rails_app; } 

...but it communicates well what I'm trying to achieve. I suppose I could get try_files to work by adding a non-esitent file before the last argument.

Is try_files the only way to do it, or is there another more idiomatic directive?