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.
Related
I have successfully setup IIS on my local development machine (dev branch - setup as localdev.me) but when I went to setup another branch (hotfix - setup as localhotfix.me) I am running into issues. The issues are due to the way the site is setup. The subdomain of the url is used to determine which Database to connect to. So going to host.localdev.me will connect to the host database. So in IIS I have the following settings for the bindings of the site.
Type Host Name Port IP Address
http localdev.me 80 *
http *.localdev.me 80 *
I can ping localdev.me with any subdomain and I get the loopback address as expected. When I then setup the hotfix branch (exactly the same as the dev but with the following bindings) I get name not resolved errors.
Type Host Name Port IP Address
http localhotfix.me 80 *
http *.localhotfix.me 80 *
Is there a reason the first setup would work and not the second? What is perhaps even stranger if I tell IIS to stop I can still ping subdomains on localdev.me and get the loopback address.
I could always get it working by manually specifying the host name in my windows hosts file but I would rather not do that as I would need to go in and edit the file every time we add a new subdomain.
EDIT: These are the specific errors I am getting.
ping localhotfix.me
Ping request could not find host localhotfix.me. Please check the name and try again.
EDIT2: I have a solution that works fairly well. It requires Acrylic DNS and installation of the Microsoft Loopback Adapter. I set the loopback adapter to a valid IP Address and set the DNS server to 127.0.0.1 then edit the AcrylicHosts file to contain entries for each domain with a wildcard. Once I did all of this I was able to ping localhotfix.me along with *.localhotfix.me. I believe the reason localdev.me worked is because it is a valid domain. The name would resolve at which point I believe IIS was able to take over. But thats really just an educated guess. But kindof makes sense as to why it worked for one and not the other.
The reason *.localdev.me works without a hosts file is because the public DNS for that domain resolves to 127.0.0.1 as long as it is not localdev.me or www.localdev.me. You can check this using nslookup *.localdev.me (replace the asterisk with anything except www) while your hosts file is empty. On the other hand, *.localhotfix.me is not registered in public DNS at all, which is why you'd need a hosts file entry for those.
I am trying to block http://127.0.0.1:8080/ in C:\Windows\System32\drivers\etc host file. so what i did is:
127.0.0.5 http://127.0.0.1:8080/AccessCtrl/login.jsp
But is not working, i can still access this site.
As I know ,hosts file is for DNS caching .
I mean one side must be an IP address and the other side must be Domain name server. So you can't do such a thing.
The hosts file only maps domain names (e.g. www.example.com) to ip addresses.
Therefore your approach won't work for two reasons:
What you're trying to block is not a domain name, but a URL
The URL you're trying to block doesn't contain a domain name, but an IP address.
You should be able to "block" the domain "localhost" this way, but you'd still be able to access http://127.0.0.1:8080/, just not http://localhost:8080/.
What you need here is a firewall, like the windows firewall.
On my Nginx I've got two hosts.
One with the values
server_name = www.mydomain.com;
root /var/www/production/myFirstWebSite;
and the other with
server_name=localhost;
root /var/www/development/mySecondWebSite;
To my domain registrar account I configured the DNS with two A record "
www IN A myIP
IN A myIP
This is cool, i can reach my first website with www.mydomain.com or mydomain.com.
Now the problem is how to reach my second website which is in development and I don't buy the domain name. And myIP/development/myScondWebSite is no more working ...
I think that the problem come from the DNS entries but I'm not sure.
Do you've got some ideas ?
Thanks in advance.
There's a couple of ways I could think of to access the localhost one.
Creating a subdomain instead of localhost
This is the best one I'd recommend, try doing something like server_name localhost.mydomain.com.
If you need to put further security, you could make it only allow a certain IP(s) or a range of IPs.
Play with your hosts file
In this specific case I would not recommend this, because you're messing with localhost it self, might break some other stuff on your machine, if it was any other name I could have said it's fine.
Use an ssh tunnel to the server
In this method you create a dynamic port on your ssh connection and set your browser to pass all traffic through tunnel which goes to the server then it's handled from there, so if you run localhost for example it would be like running localhost from over there, but since this involved a browser setting, you need to remember to disable it after you disconnect the ssh connection otherwise the browser would return an error saying that the proxy server is refusing the connection.
Using a local Nginx as a proxy
This one I just came up with right now, and I can't say If it would work or not, the 3 before I've worked with before and I know they work.
You'd set a certain domain name that your local nginx would capture and then proxy it to the remote server, but edit the host header setting it to localhost instead, that way it would match the localhost in the remote machine, if this one works it would not need any setting to be turned on and off every time.
Out of all these, I'd recommend the first one first (if it's an option), then try the last one if you don't want to keep turning things on and off before and after each setting.
In Project-Open tool, aolserver is used to host the application and is accessed using the ip address of the server like 172.XX.XX.XX:8000.
Now I don't want to make this ip address public. I tried to create and use url (by making some changes in the config.tcl ) for this but couldn't do so.
Please let me know if my question is not clear enough.
thanks in advance!!!
Well, your question isn't totally clear, but I think what you want is for your website to appear on a URL, such as www.example.com. To do this with AOLserver, you need to edit the /web/server/etc/config.tcl file and edit this line (changing www.example.com to whatever URL you want).
set hostname www.example.com
Then restart AOLserver. You might also want to set the port to 80. This requires root access, and you may also need to pass -b to AOLserver in your startup script.
I understand you are running ]project-open[ on a local server on port 8000 and you want to make this service visible to the Internet, right? There are several steps required:
In your Internet router, you will need to open a port (80 or 8000).
You need to forward incoming traffic on your router to the ]project-open[ server. You can do this using a forwarding rule or similar. Please check your router.
You probably want to setup a URL using DynDns, Dynu or other DNS providers pointing to your Internet router, and changing in case your router's IP is also changing (SOHO router).
In ]po[ you will need to set the redirection URL accordingly. Depending on the port, you may want to set Admin -> Parameters -> "SuppressHTTPPort" to 1
Which OS will you be using to access this server? If you will be using a LInux machine you would put the host name into your /etc/host file with the desired name:
For example:
/etc/hosts:
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.23.108 myprojecturl
The line 192.168.23.108 will provide for you to use myprojecturl to access the site rather than the ip number 192.168.23.108 (from that machine).
From a Windows machine you could do the same. The host file is located in a different plaice ().
c:\windows\system32\drivers\etc\hosts:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.168.23.108 myprojecturl
The last line is an example of what you would add to make "myprojecturl" the host name for pulling up the site instead of having to remember the ip numbers to type in.
If you're trying to make generated urls be different from the where the server is listening, you need to set the location parameter in the nssock configuration.
in the config fie is a section like this:
ns_section ns/server/${server}/module/nssock
ns_param timeout 120
ns_param address $address
ns_param hostname $hostname
ns_param port $httpport
Add in
ns_param location http://my.host.com/
see http://blog.gmane.org/gmane.comp.web.aolserver/month=20110201
My program uploads a picture in the ftp server and I need to get the http address for the picture. How can I do it so it would be dynamic and independent of a specific server?
There is nothing whatsoever that says it has an HTTP address, and if it does it is totally under the control of the server configuration. There is no defined mapping.
Does not exist any fixed rule that associate an http address from ftp address. And it does not depends on Java.
It's only a configuration problem, whatever language you use; you have to know when you upload a file on a ftp server if that file will be reachable through an HTTP server and what address it will have.
Paths on ftp servers and http server do not correlate. The only solution I could imagine is:
Know the "server root path" for both HTTP and FTP server
Know the path relative to this root
Combine these two to the full path
Nevertheless there is no guarantee that it will work in every case. It relies on the fact that you can establish a manual mapping of the server roots (see EJP's answer).