Pergunta

I finished developed an app that features a downloading system that is hosted with NGINX at:

http://dashboard.myapp.com

The URL for downloads is:

http://dashboard.myapp.com/download/file-slug

This page is a regular PHP page that will require some user input and then PHP handles the actual file download, it's not the direct path for the file.

Since these download URLs will be made publicly available, I want to ditch that dashboard subdomain.

The default domain (myapp.com) is already working with a wordpress setup with this:

    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

Is there an easy way to get the:

http://myapp.com/download/file-slug

to act as if:

http://dashboard.myapp.com/download/file-slug

was accessed, without actually redirecting?

Foi útil?

Solução

Try this - Place in your server block for myapp.com, anywhere outside another location block. Set the root to the same root as the dashboard subdomain (if on the same server). The script would see itself as being hosed at myapp.com instead of dashboard.myapp.com, but it should retain the remainder of the framework rules. If this doesn't work, try the next option.

location /download/file-slug { 
    root /path/folder;  
    try_files  $uri $uri/ /index.php?q=$uri&$args;
}

Another option is to proxy through Nginx. This option actually runs the script on the current location, accessing it like a client would through dashboard.myapp.com. See proxy_pass documentation on Nginx.org.

location /download/file-slug { proxy_pass http://dashboard.myapp.com/download/file-slug; }

Outras dicas

I was able to work it out with Nginx only.

Inside the myapp.com config file I added:

    location ~ /download/(.*) {
            resolver 8.8.8.8; 
            proxy_pass http://dashboard.myapp.com/download/$1;
    }

The resolver 8.8.8.8 is actually using Google DNS. Without this line I was getting a "no resolver defined to resolve" error.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top