1

I'm really confused how to make my Apache2 web server public. I've setup everything and when I type localhost:80 it comes up properly. But, I need very clear and detailed instructions on how to make it public! And also have it used by its alias which I set to pcpcpc12.com

[EDIT]

Output of /var/log/apache2/access.log

127.0.0.1 - - [16/Mar/2016:20:04:23 +0000] "GET / HTTP/1.1" 200 3594 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:04:23 +0000] "GET /icons/ubuntu-logo.png HTTP/1.1" 200 3688 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:04:24 +0000] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:04:24 +0000] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:10:34 +0000] "GET / HTTP/1.1" 200 661 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:10:34 +0000] "GET /icons/blank.gif HTTP/1.1" 200 430 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:10:34 +0000] "GET /icons/folder.gif HTTP/1.1" 200 507 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:10:40 +0000] "GET /pcpcpc12.com/ HTTP/1.1" 200 3594 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:11:31 +0000] "GET /pcpcpc12.com/ HTTP/1.1" 200 732 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:11:31 +0000] "GET /icons/back.gif HTTP/1.1" 200 498 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:11:31 +0000] "GET /icons/blank.gif HTTP/1.1" 304 178 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:11:31 +0000] "GET /icons/folder.gif HTTP/1.1" 304 178 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:11:42 +0000] "GET /pcpcpc12.com/public_html/ HTTP/1.1" 200 280 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:14:26 +0000] "GET /pcpcpc12.com/ HTTP/1.1" 200 734 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:14:26 +0000] "GET /icons/blank.gif HTTP/1.1" 304 178 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:14:26 +0000] "GET /icons/back.gif HTTP/1.1" 304 178 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:14:26 +0000] "GET /icons/folder.gif HTTP/1.1" 304 178 "http://localhost/pcpcpc12.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:14:44 +0000] "GET / HTTP/1.1" 200 280 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:51:41 +0000] "GET / HTTP/1.1" 200 548 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:51:42 +0000] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:51:42 +0000] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"
127.0.0.1 - - [16/Mar/2016:20:51:45 +0000] "GET /pcpcpc12.com/public_html/index_two.html HTTP/1.1" 200 505 "http://localhost/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0"

Output of error.log

[Wed Mar 16 19:18:41.713986 2016] [mpm_event:notice] [pid 4282:tid 140223239657344] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming normal operations
[Wed Mar 16 19:18:41.714259 2016] [core:notice] [pid 4282:tid 140223239657344] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jan 01 00:00:48.990306 2013] [mpm_event:notice] [pid 1316:tid 140375846848384] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming normal operations
[Tue Jan 01 00:00:49.019771 2013] [core:notice] [pid 1316:tid 140375846848384] AH00094: Command line: '/usr/sbin/apache2'
d a i s y
  • 5,511
  • What have you done so far? – techraf Mar 17 '16 at 08:35
  • 1
    and how is your network set up? Are you behind a router? If you are the most of this is hardware related and not a problem in apache. You can use /var/log/apache* to see if anything arrives at apache. If not the problem lies elsewhere. – Rinzwind Mar 17 '16 at 08:44
  • @Rinzwind , I am behind a HG533 TalkTalk router. There is error.log, which is way too long for a comment, so it's cut down [Wed Mar 16 19:18:41.713986 2016] [mpm_event:notice] [pid 4282:tid 140223239657344] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming normal operations [Wed Mar 16 19:18:41.714259 2016] [core:notice] [pid 4282:tid 140223239657344] AH00094: Command line: '/usr/sbin/apache2' [Tue Jan 01 00:00:48.990306 2013] [mpm_event:notice] [pid 1316:tid 140375846848384] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming normal operations' – Ubuntulover Mar 17 '16 at 15:42
  • The stuff you posted just shows accesses from your lan and is not helpful. Have you forwarded port 80 in your router to the server? – Organic Marble Mar 17 '16 at 16:00
  • @OrganicMarble no, I'm not sure how to with the router my pc is hooked up to. – Ubuntulover Mar 17 '16 at 19:17
  • 1
    You have to do that to get it to work, so that when a request comes in from the net on port 80, it gets sent to the webserver. Look in the router config menus for port forwarding and set port 80 to be forwarded to your webserver. – Organic Marble Mar 17 '16 at 19:25
  • @OrganicMarble well. Interface: nas_0_38
    Protocol: TCP/UDP

    Remote host:
    External start port: 8080
    External end port: 8080
    Internal host:
    Internal port: 8080
    Mapping name: pcpcpc12.com

    – Ubuntulover Mar 18 '16 at 22:40
  • I'm not sure what your comment is intended to convey. On my router after I configure it, the menu page says "Service name: HTTP" "External Start Port:80" "Internal Start Port:80" "Internal IP address: XXX.XXX.XXX.XXX" – Organic Marble Mar 18 '16 at 22:54
  • @Grogu gave an amazing tutorial below showing how to make an ip public. However, keep in mind that many internet providers limit the possibility of using ports 443 and 80. They usually do this to push you into a business plan. I did everything that was mentioned by him and found that it didn't work because my provider confirmed having an external firewall blocking the ports. – Mithsew Nov 23 '22 at 20:10

2 Answers2

2

when you "set the alias to pcpcpc12.com", others will not be able to view it unless you create a public DNS record. this will require knowing your public IP address. you can just google "what's my public IP"

If you own pcpcpc12.com, registered through godaddy or someone, then they should have an interface for you to create an A host record, use your public IP for that.

If you don't own the domain, then others can still reach your website by typing your public IP address in their browser, for example, http://192.168.0.1/ (your public IP will not start with 192.168)

since you mentioned in the comments that you are using a TalkTalk home gateway router, I'm assuming you're using a residential internet connection. Depending on your ISP, such as Cox (my beloved ISP), they may choose to block your public http port as an incentive to get you to upgrade to a costly business internet connection.

You can check by going away from home somewhere on some other network, and running network map. Install the utility sudo apt-get install nmap and then run the command nmap -Pn -p 80 192.168.0.1 and change the 192.168.0.1 IP to the public IP from step one. With luck, you'll get an open scan like this:

Starting Nmap 6.40 ( http://nmap.org ) at 2016-03-22 22:17 CDT
Nmap scan report for 192.168.0.1
Host is up (0.0028s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

Otherwise, you'll get a filtered scan like this:

Starting Nmap 6.40 ( http://nmap.org ) at 2016-03-22 22:19 CDT
Nmap scan report for 192.168.0.1
Host is up.
PORT   STATE    SERVICE
80/tcp filtered http

Nmap done: 1 IP address (1 host up) scanned in 2.58 seconds

In this case, then others can still reach you on a non-blocked port. 8080 is a popular choice. you will need to adjust the settings in your router to port forward map your incoming external port 8080 to your internal port 80 of the internal IP of your server. You will only have one public IP, but you will have a different internal IP for every device on your network. Internal network IPs usually start with 192.168. or 10. You can find out your internal IP by running the terminal command ifconfig

Once you have that setup correctly, then the world will be able to reach your site at http://192.168.0.1:8080, again making sure to use your public IP and not the 192.168.

Jeff Puckett
  • 1,741
0

As a newbie Linux user, I was also lost trying to understand how to make an Apache website public on my VPS. Here's a complete tutorial I about how to make an Apache website public available that should answer your question and hopefully help future newbies as well.

Prerequisites

This tutorial assumes you already have the following:

  • VPS from a host like Bluehost or AWS (whatever)
  • Ownership of a public domain name

In my situation, I have a Linux VPS with OVH.com, and I own a domain with name.com. Notice this is 2 different companies; hence two different servers.

Detailed Steps

Set up a website on Apache2

Start by setting up your website on your VPS.

Note: This portion of the tutorial isn't about configuring your Linux VPS. I assume you have it ready to go for production.

  1. Create a directory for your website

    Open a terminal and create a directory for your website. Replace domain.com in all steps below with the name of your site:

    mkdir -p /var/www/domain.com/public_html
    

    Make folder writable to avoid issues further down the road:

    chmod -R 755 /var/www

  2. Create an index page for testing

    gedit /var/www/domain.com/public_html/index.html
    

    And add something like testing for domain.com.

    Note: If you experience connection issues opening gedit, open other terminal and, as a regular user, run the command xhost +. After that, try running gedit again. For more info about this issue please see here.

  3. Copy default config to a new file:

    cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/domain.com.conf
    
  4. Edit the new config file

    gedit /etc/apache2/sites-available/domain.com.conf
    

    Add/edit the following:

    <VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/domain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Important: The ServerAlias is the name you want people to use to access your Apache website on the internet.

  5. Enable the new config file

    By default, Apache is set to read 000-default.conf file. However in our previous step we made a new config file. So we need to disable the default and enable the new one we created.

    a2dissite 000-default.conf
    a2ensite domain.com.conf
    

Making Website Public

To make your Apache website public, we need to configure DNS servers.

  1. Log into your VPS

    Login to your VPS account. In my case, I use ovh.com for Linux VPS, but yours may be different. Login to your account and take note of the IP address usually found the under IPv4 settings. Copy to clipboard.

  2. Log into your cpanel

    In my situation, I'm paying two different companies. One for VPS and other one for domains. This is because my VPS provider which I've been using for many years does not sell domains, just private servers. You can skip this step if both your VPS and domain are with the same provider.

  3. Create DNS

    In your account where your domain is, click on Manage DNS or something similar. Click on add new record. This should look something similar to photo below:

    enter image description here

    Fill in the fields:

    Host: Use the ServerAlias setting from above.

    Answer: Enter or paste your VPS IP that we previously copied.

  4. Save the record

Voila! Visit your Apache website online and you should see testing for domain.com or whatever you wrote to test the page.

Next Steps: SSL for Apache

At this point, your domain will be HTTP. This will render your Apache website insecure and cause a warning in the browser. We certainly do not want to scare your visitors away with that!

To provide SSL/TLS (HTTPS), I recommend Certbot.

I will not go in details about how to do this, but visit their site. The tutorial is pretty straightforward.

NotTheDr01ds
  • 17,888
Grogu
  • 117
  • Why the downvote? – Grogu Feb 02 '22 at 01:06
  • I would do the same. There is tons of pretty text here but no actual question. This is a question and answer site not a place for someone that thinks they are teaching a class. – David Feb 02 '22 at 05:41
  • @David This is a useful answer to help the Youth, the not-so-Youth and other newbies. A resourceful answer like this one would get me tons of upvotes on stackoverflow. OP asked a question about making a website public with Apache and I delivered an answer pacted with great material. – Grogu Feb 02 '22 at 19:22
  • he is teaching how to make the ip public with domain name. It's unreasonable downvote. – Mithsew Nov 23 '22 at 20:33