EDIT: Just figure it out! My configuration is ok. It because my cancellation of CNAME is not valid yet. After a while it automatically map by Nginx.
========================================================================
I try to url masking with Nginx on heroku. It works great until I use a CNAME on my entry domain.
When I directly keyup https://foobar.herokuapp.com/search-beta, request will be forward to FORWARD_HOST as expect with the url correct. But when I try to access my app with a CNAME (let's say we have a CNAME https://www.foobar.com to https://foobar.herokuapp.com) like https://www.foobar.com/search-beta, the request will be redirect to my FORWARD_HOST.
Is there anything I miss? Can any one give me some tips?
thanks
My Nginx config
daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
events {
use epoll;
accept_mutex on;
worker_connections 1024;
}
http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;
server_tokens off;
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log logs/nginx/access.log l2met;
error_log logs/nginx/error.log;
include mime.types;
default_type application/octet-stream;
sendfile on;
#Must read the body in 5 seconds.
client_body_timeout 5;
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
keepalive_timeout 5;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
location /assets {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $proxy_pass http://app_server;
if ($http_referer ~ "search-beta") {
set $proxy_pass <%= ENV["FORWARD_HOST"] %>;
}
proxy_pass $proxy_pass;
}
location /search-beta {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_pass <%= ENV["FORWARD_HOST"] %>;
}
}
}