How to set a name for Apache server? - html

I created successfully a apache server but I dont want to connect to it by typing 192.168.0.102, I want a normal url like www.google.com. How can I do that? I went to httpd.conf and found the ServerName line but setting it to something like www.mysite.com doesnt seem to work. I also tried to use my external ip(https://www.whatismyip.com) as server name but it doesnt connect. It only works if I try to connect to 192.168.0.102 or localhost. How do i solve this? Thanks

There are three basic things you need to know.
Virtual name hosting
HTTP allows multiple websites to be hosted on the same IP address and port. The client uses the Host request header to tell the server which site it wants to get data for.
ServerName is used as part of this.
… but the client needs to know how to send a request to the server first.
DNS
When a client makes a request to a server, it uses the IP address of the server in order to allow it to be passed over the network (or networks) to it. It is the address.
IP addresses are sequence so of numbers, which aren't very friendly for humans to work with.
DNS translates friendly names (like www.example.com) into IP addresses.
The client has to look up the name to find the IP address. It normally does this through the main DNS system, and in order to get your name linked to your IP address you will need to find a domain name registrar and pay them.
It is also possible to set up DNS at a local level on a private network, and on a computer-by-computer level using a hosts file.
Routing
The IP address of the server has to be routable from the computer the client is running on.
192.168.0.102 is a private address, accessibly only on the same LAN. To make it accessible to clients on the Internet you need to either:
Set up your router to use port forwarding and then use the Internet facing IP address of the router (which https://www.whatismyip.com tells you) or
Give your computer a public IP address and configure your router to route traffic to it (this generally isn't possible on consumer grade routers).

In short, you can't. 192.168.0.102 is not accessible from the Internet it is internal IP.
But you have some alternatives, like if you like to access your computer from a hostname you can use dynamic DNS servers.
Or you want to test your code on a spectacular domain, you can add 192.168.0.102 with a domain to your hosts file, then only you can use this domain with your local computer.
But, If you really want to serve some content to the Internet from your local computer you have to find a DNS server service (like cloudflare) to point your domain to your public Internet ip not to 192.168.0.102.

You configure the virtual host and set the server name to the domain name you want. After that, Apache will check the requests and will use that virtual host if a request was made for that domain name. In order for that to work, that domain should point to your IP address where the server is running.
If you want to test if the configuration works, edit your /etc/hosts file and add that domain name to 127.0.0.1. After that you will be able to access to that virtual host if you try to access to that domain name from your browser.
More info here : https://httpd.apache.org/docs/current/vhosts/name-based.html

Related

How can I share the output of an html code written in visual studio code with someone else?

I don't think that we can share the link that we get from the live server extension to someone else for viewing our web page.
kindly advise me. I am new to front-end development.
By default LiveServer will listen for network connections on 127.0.0.1 and is available only to clients running on the same computer.
You can change that in the settings (under Live Server > Settings:Host) to specify any IP address allocated to the computer you are working on. You can also use 0.0.0.0 for every IP address allocated to that computer.
Anyone who can reach the IP address you select (which is typically anyone on the same LAN as you) can then visit http://192.0.0.10:5500/ to see the site. (Replace the IP address in that example with the one assigned to your computer that you selected above).
For someone to access the server from a different network, you will need to have an IP address on the public Internet. Typically you would get this by following the above instructions and then configuring your router to forward port 5500 from its Internet facing IP address to the IP address of your computer on the LAN.
You can also look at tunnelling a connection with by creating an SSH tunnel manually or using a service like ngrok which connects a URL on the public Internet to your local server (note that this removes the requirement to change the Live Server configuration away from 127.0.0.1).

Deploy Content on Private IP Address?

I was reading about port forwarding which got me excited to try it myself.
But I'm stuck on the first step, given an html file how can I deploy it on my laptop's private ip address with custom port?
For example, imagine my laptop's ip is 10.0.0.4
Then when typing: 10.0.0.4:9011 in the browser I want to see the contents of the file.
Port forwarding would only be necessary if you want to make your laptop/server accessible outer your home network.
It is not only about port forwarding, you also need to install and run a server service like apache if you want to open that html file in a browser.
Additionally your laptop's public IP is probably not static. Almost all internet providers give you a dynamic IP for personal use. Which means that you need to use a different IP everyday to access that file.
However if you want to use that file only in your home network, then you still need a service like apache to host your file but you dont need a port forwarding + you can make your local IP static.
Here is a useful blog to host a website on your pc

how to configure Zabbix agent if I don't IP of client PC?

Can I connect Zabbix server if I don't have client's IP , to be more specific I don't have any information about client except for information that I'm going to put in Zabbix agent config file like some name.
For example: I have several hosts in several different local networks and I want to get some information from them, but I don't know the IP address of host or router and I can't setup port forwarding on router, I just want to setup agent to be able to connect server over the internet that's all. Is that even possible?
Yes, use the active agent items only. Set the Zabbix server IP address in the ServerActive parameter and make sure the agent hostname matches the host name in the server (not the IP, not the DNS name).

Why is connection failing when port-forwarding with dynamic dns in same network

I have a MySQL database running on my raspberry pi.
To access it I use dynamic DNS (duckdns) when I am outside of my network, but I would like to access it with same dynamic domain name when I am inside my network. However it is not working and I always get connection refused.
I would like somehow enable it so I do not have to change in app.config MySQL server address from my dynamic domain to localhost when I am inside my local network.
You'll need a gateway router that supports NAT hairpinning. Many consumer-grade units (and some supposedly commercial-grade equipment) doesn't support this. Either yours doesn't, or you need to find an option to enable it.
When you try to connect to the public IP address from inside the network, the router probably assumes that you want to connect to the router itself.
My cable modem's built-in router at home understands how to do this. When I access my server from the laptop, and connect to the public IP from inside, the router (inside the cable modem) does a transformation on the packets so that my server sees my connection coming from the router's IP address, not my laptop's IP address.
This is what has to happen, because when the server responds, it will respond to the machine that connected to it. If it responded to the laptop's address, the laptop would reject the traffic, since it would be coming from ther server's internal IP, which is not the IP address I connected to. So, it responds to the router, which does a second transform on the packet address, replacing the server's internal IP with the external IP. Remembering the session from previous traffic, the router then sends the packet back to the laptop.
Ultimately this setup can't possibly work for you without the complicity of your router, which may not have that capability.
Some routers, however, have a DNS proxy that will allow you to create static entries. My former DSL modem could not hairpin NAT connections, but it had a way to create DNS entries that would be used to respond to internal DNS queries for a specific host... with a different IP than the one that DNS otherwise provided. That's an alternative workaround if the router supports it.

dyndns equivalent for ports? (so that port changes don't require config file changes)

DynDNS et. al. are great for not having to put IP addresses in config files... I put the dyndns domain in the config and if I ever want to change the server location I just update it in one place, and the config stays the same. But what if I want to change the port number that's used? Is there an equivalent for ports - so that I can also get what port to connect to from some service just like I get the IP from DynDNS? Or what's another solution (besides not changing the ports)?
DynDNS and DNS in general has the main purpose of not having to remember a host by its IP address. The DynDNS part comes is mostly to solve the issue of people who don't have static IP addresses, and they occasionally get new IP addresses when their DHCP leases expire.
The original intention wasn't really meant to account for someone purposely changing their IP address or port numbers. Usually a service is on a well known port that doesn't change, such has 80 for http. Depending on the protocol, you could set up a well-known port, and then have it redirect to a different port. As an example, some websites will redirect port 80 to 8080, but this is protocol dependent. This also won't work for a lot of other protocols, and you're usually stuck with the port you choose.
Using DynDNS I access three different machines behind the same router by simply adding a colon and the port number just as if I were adding it to a static IP address (ie myhome-computer.dyndns.biz:1234 ). Each port points to a different internal ip in the router. This works fine with my free host account. However, I am not aware of a port identifier that could report as the DynDNS host app does.