I have a web app running on a nginx server on local ip 192.168.0.30:80
I have this in my etc/hosts
127.0.0.1 w.myapp.in
If someone accesses my app using a "w" subdomain, it shows a webdav interface, otherwise it runs normally
(for example, someone calls http://myapp.in , it goes into the app, and http://w.myapp.in goes into webdav interface - this is done within the app, nginx has nothing to do with it)
Because I don't have a dns or anything like that, users must access the app by ip. A problem appears if someone wants to access the webdav interface, because you cannot access the app by a subdomain - unless you write a line in your local hosts file, which is not a solution)
A possible solution
If it's possible to setup the nginx server so that if someone calls http://192.168.0.30 (on port 80), it goes normally into the app, but if a user tries to access say http://192.168.0.30:81 (another defined port) it redirects internally to w.myapp.in, and the app sees the subdomain
Given the app, can this be done? If yes, what should I put in the nginx config file? And if you guys think of a better solution, I'm open to any.
Yes, you can get nginx to listen on two ports and proxy requests on different port numbers appropriately. Something like this:
I would try the rewrite directive. Have one server listening on port 80, and optionally rewriting to a real server name. And another server listening on port 81, and rewriting to the 'w' subdomain. Not 100% sure this will work, but it's worth a shot.
http://wiki.nginx.org/HttpRewriteModule