subdomain with rewriteModule - asp.net

i'm using this rule for rewriting subdomain
and i'm corrected host file to
127.0.0.1 domain.net
when user typed news.domain.net/default.aspx it must return domain.net/news/default.aspx but browser showed Address not found.
how do i?
please help
thanks all

When you add the entry to your HOSTS file, it will only correct the exact DNS lookup - in your example, "Domain.net" would resolve to 127.0.0.1, but "news.domain.net" won't resolve to anything, since there's no server at that address. If you add an entry to your HOSTS file for:
127.0.0.1 news.domain.com
That will resolve that domain to your local machine, and then you can configure IIS to rewrite that URL to whatever you want.

Related

Nginx is not preserving the path when using domain name

My application is running on Nginx webserver. I can access the application through my server DNS name. Example :
ec2-xxxxxx/myapp
If I enter the address without /myapp, I can see Nginx 403 Forbidden error.
I have now created a new sub-domain on my Domain control panel and Forwarding the request to the root address.
I can see the 403 error when accessing the sub-domain, however when I enter subdomain.mydomain.com/myapp, I still see the 403 Forbidden error. Somehow the relative path is not being preserved when calling from the domain name.
Is this problem related to resolving DNS at my domain registry, or it's an Nginx config issue?
Its a nginx config issue. You need to create the virtual host for your subdomain. Post that you should be able to access your app from your subdomain.
The problem was with the Domain registry (GoDaddy) and had nothing to do with Nginx config.
After moving from GoDaddy to AWS Route53, I can easily access sub-domain with it's relative paths.

IIS Adding URL instead of IP

I have a local only ASP.NET MVC app hosted in IIS, and I was wondering how I could use a URL instead of an IP? At the moment I access it using http://127.0.0.1, but I'd like something like http://foo instead
In IIS, you need to add a binding to the website, here you can specify the hostname i.e. foo.xyz.com
However, you will need to make sure that the DNS resolves that hostname to your IP address
You could add this line to your host file:
127.0.0.1 foo
You can find the host file here:
C:\Windows\System32\drivers\etc

what is the difference between hosts file and nginx configure file?

if I have an entry in my hosts file ,and also the hostname is in the server block of the nginx configure file ,I wonder which file is applied first and does what specific,could someone tell me ?
The hosts file is used by your OS to resolve hostnames to IPs and is usually evaluated first (can be customized - at least on unix based OS). If you tell an application to look for some host, e.g. www.example.com, it looks up the name in the hosts file and uses the IP to connect to that host. In case the hostname can't be found in the file, it will usually ask the configured DNS servers for it.. See Hosts File and DNS for more info.
The hostname in the server block on the other side is used by nginx to determine the appropriate action to be taken. nginx evaluates the HOST header in the request and tries to match it against the values configured in the server_name variables in each block. See Server names and How nginx processes a request.

Add subdomain to localhost URL

I am writing an web application that behaves differently depending on a url prefix. The format is something like:
https://myprefix.mycompany.com
The web app behaves differently based on myprefix. My web app extract that part from the URL and act on that.
However, when I test on my local, I use an localhost address:
https://localhost:1234
I counldn't do something like:
https://myprefix.localhost:1234
What is the best way for me to test this scenario?
Many thanks
Unfortunately, because localhost is not a proper domain, you can't add a subdomain to it like that. You can, however, trick your computer into thinking it owns a specific domain and test things that way. For instance, if you have a UNIX-based operating system, open (as root) the file /etc/hosts and add a line (or lines) like this:
127.0.0.1 example.com
127.0.0.1 subdomain.example.com
Your computer will now treat both example.com and subdomain.example.com as belonging to itself. If you visit either in your web browser, they will work the same, in principle, as localhost, but your web server will see the correct domain in its Host header.
I'm not sure about same behaviour on windows. I'm working on linux mint.
You can use lvh.me:port as a local domain. You can imagine that your project is deployed on localhost:port on this domain.
Instead of sub.localhost:port you've to use sub.lvh.me:port
UPDATE
sub.localhost:port works on Chrome.
Note: Firefox automatically adds www. at the beginning of entered domain that can cause problems with subdomains testing
For Windows users, based on this answer and per this comment, you can achieve this by adding ports to localhost via the hosts file that resides at this path:
C:\Windows\System32\drivers\etc\hosts
And append lines like the following to it:
127.0.0.1 example.com
127.0.0.1 subdomain.example.com
One-Line Solution for Windows
Open PowerShell as Administrator and run the following command, replacing sub.mydomain.com with whatever you want.
"`n127.0.0.1 sub.mydomain.com" | Out-File C:\Windows\System32\drivers\etc\hosts -encoding ASCII -append
Breakdown:
`n - newline
127.0.0.1 - loopback address
sub.mydomain.com - domain name
| Out-File C:\Windows\System32\drivers\etc\hosts - pipe the string to the hosts
-encoding ASCII - correct encoding
-append - append to end of file (important!)
You should be using the .test domain for things like that. That is what .test is for. localhost is not supposed to have any subdomains.
To do so violates the approved RFC standards. localhost has an A record and in IPv6 environments, an AAAA record. All other DNS record types, including SOA are forbidden.
Without an SOA record, it cannot be a zone apex that has sub-records, so no subdomains nor delegations are permitted. Even the recent RFC draft titled Let localhost be localhost is consistent with this.
https://myprefix.mycompany.localhost:1234
This should do the trick. Because localhost is a top-level-domain, it behaves like a .com in production code.
It took me a bit of time to find public wildcard DNS domains pointing to localhost so I'm leaving it here for future reference.
The domain that worked for me is localtest.me. That domain and its sub-domains resolve to 127.0.0.1 and ::1.
For example:
$ host localtest.me
localtest.me has address 127.0.0.1
localtest.me has IPv6 address ::1
$ host some-sub-domain.localtest.me
some-sub-domain.localtest.me has address 127.0.0.1
some-sub-domain.localtest.me has IPv6 address ::1
A maintained list of other public wildcard DNS domains that point to localhost can be found in this Gist.
From WSL in Windows:
First navigate to /mnt/c/Windows/System32/drivers/etc(Navigate cause, you may find more interesting files. Don't play here, but see what do they do)
Then do nano hosts(add at very bottom)
127.0.0.1 random.com
127.0.0.1 auth.random.com

IIS Subdomain Host Headers Not Working

Using IIS 7, I have an existing website, example.com, and I have added another website to which I'd like the URL, sub.example.com to point. I've set up the host headers for this, but it does not work. Trying to ping the subdomain URL give the message "Ping request could not find host sub.example.com. Please check the name and try again."
Should a DNS setting perhaps be set?
The subdomain must be set in the DNS or it will not resolve to an IP address. Just having it defined in IIS is not enough. The client computer must be able to translate the name into a meaningful server address.

Resources