I am running Apache Tomcat on my PC. My PC is connected to a router in my house and the router is connected to my ISP. Now I want to run a server on my PC so that my friend can view my site hosted on my PC.
If I go to the site https://whatismyip.com I know that my IP address is xx.xx.xx.xx. This is the IP of my router I guess. If I type http://xx.xx.xx.xx in my browser then my router asks for a username and password. This means that my friend can connect to my router. How can I allow them to see the site hosted on Tomcat running on my PC?
I don't want to use commercial hosting and I want to use my PC only as a server due to some reasons.
The internal IP of my router is 188.8.131.52 and of my PC is 184.108.40.206.
Make sure to change your router password and lock down your router, since you will be making your IP publicly available, the configuration of your router is very important. It probably would be a good idea to download the latest firmware to prevent security exploits.
Forward your web requests to your local machine, on your router. Look for a "port forwarding" option, which will force all requests on a certain port your router to be forwarded to your machine's IP address
try to ensure that your internal IP address remains the same. Some advanced routers can reserve a certain IP address for your computer's MAC address, so make this configuration to your router. If you router software cannot do this, you probably will have to update your internal IP address in the "port forwarding" mapping whenever your computer reboots (or gets another IP address somehow). You can also confgure your computer to use a hard coded internal IP address, but this could add additional issues too out of scope to discuss here.
if you're ISP provides you with a dynamic IP address, it can get to be a hassle sending your friend your new IP address every time it changes, so you could sign up for a dynamic IP service (www.dyndns.org) which will have a program that will update a dns entry for you. Most modern routers have this server built into the firmware, you can look for it then you don't have to run the software on your machine.
for security reasons, reduce the number of other requests that are being sent to this machine (e.g. windows file sharing, ftp, bit torrent, etc etc).
Port 80 is the default port used by web browsers and servers, so when you access a site http://www.mysite.com, you're requesting it on port 80)
Port 8009 is the default port used by tomcat, so if you're using tomcat, you may want to replace port 80 with port 8009 below.
You don't have to do any other port configuration for the web server on your local machine, you can have your router do the mapping and leave the web server running on port 80 or 8009 on your machine.
Example, say i want to use port 12345, then I can configure my router so that any requests on port 12345 on my router will be sent to port 80 (or 8009) on my local machine. This allows you to be able to access our web server on that machine simply by going to http://localhost/ or http://localhost:8009 . Other internal machines on your network will have to access by Ip address (http://192.168.1.x) or you can edit yoru hosts files and assign a name.
It's important to know that most ISP's block port 80 ( and other common ports) from being used as a web server, so even if you have everything configured property on your end, your friend still may not be able to hit port 80 on your machine. This is typically done so that ISP customers will fork out more cash for their "business" offerings. Because of this, you will probably have to open your router on another port if you really want your friend to access your web server. You'll want to stay away from low number ports, and you'll want to avoid using the port your router is configured from as well.
If you do all of the above correctly, you should be able to have a stable URL (such as http://myusername.dyndns.org:12345 ) that your friends can bookmark and use at will
From your router forward port 80 from your router to your pc ip address. Once this is done, tell your friend to access your website by using http://xx.xx.xx.xx/webAppName. Here xx.xx.xx.xx is your IP address and webAppName is your website project.
By default the ISPs will block port 8080 so you have to change the port tomcat uses.
If you arent interested in port forwarding or if it sounds complicated, most routers have setting called the DMZ. Put your webserver (the machine that hosts the website) in the DMZ to allow it to be seen from the outside world. Then, if you havent registered a domain name, have your friend type in your IP into his browser.
You will need to set up "port forwarding" on the router of port 80 (http) to your PC and also I recommend setting up "static DHCP" so that the router always assigns the same IP to your PC when it boots.
Note that you are exposing your PC to the world of hackers when you do this. Make sure you have a current version of apache/tomcat installed and that you apply updates regularly.
If your router supports it you may want to set up "dynamic DNS" to give your machine a permanent name on the internet (instead of a sometimes changing IP #.) Check out dyndns.com and look at their free dynamic DNS options.