Score:0

Apache Rewrite to Nginx with ProxyPass

ck flag

I'm trying to redirect an Subdomain hosted on an Apache Webserver* with .htaccess to an external URL with hiding this external URL. The .htaccess file looks like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.domain\.com [NC]
RewriteRule ^(.*) http://external-domain.com/$1 [P]

How I must configure the Nginx site? The site is very simple and works if called directly in the local network:

server {
    listen 80;

    server_name sub.domain.com;

    root /usr/share/nginx/html/sub.domain.com;
    index index.html;
}

I guess there must be some ProxyPass magic, but I cannot figure out what. It must be something like

location ^~ / {    
    proxy_pass http://localhost;
    proxy_set_header X-Real-IP 127.0.0.1;
    proxy_set_header Host sub.domain.com;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

but this does not work. I would appreciate any help. Thanks...

*The Webserver is hosted by an simple Provider, no special configurations can be made

Score:0
ck flag

I took the simplest solution. I have deleted the subdomain and added an CNAME DNS Record. That works.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.