How To Set Up Default Port?

January 11, 2017 860 views
Apache Networking Control Panels

We have our company website which runs on nodejs framework Sails, within Port :2000
We hired a private DNS ( www.thundersolucoes.com.br ) And apache is currently redirecting to our DO Ip ( 104.131.25.124:2000 ) but on the browser it's visible the IP instead of the URL name for the website, we're from brazil, so the company that sells domains which we registered is called Registro.br ( https://registro.br/ )

I'd like to know which configuration should be done in order for the website show it's correct name using the port 2000 as default whenever an user access our domain.

Thanks in Advance, best regards!

2 Answers

Hey, great question!

It looks like you're currently using a redirect rather than a reverse_proxy so users are actually redirected to port 2000 on your IP. This may cause problems for users that are behind restrictive firewalls.

This section of the official documentation covers how to set up a reverse proxy configuration on Apache.

Personally I find it easier to work with Nginx for this purpose than Apache but this is in part, a matter of preference. I have several of my services which are written in Ruby and other languages running behind nginx in this fashion.

If you'd like to try this configuration instead you can follow the steps below.

1.) Remove Apache

apt-get update
apt-get remove apache2

2.) Install NGINX

apt-get install nginx

3.) Open the default configuration file /etc/nginx/sites-enabled/default and modify it so it looks like this:

server {

        listen 80default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
        proxy_pass http://localhost:2000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

}

4.) Restart nginx for the change to take effect:

service nginx restart

Your service running on port 2000 should now be viewable as www.thundersolucoes.com.br without the IP or port shown in the address bar. All traffic will pass over port 80 rather than directing the user themselves to port 2000.

  • Will this remove /phpMyAdmin as well?
    Since apache was installed with phpMyAdmin and MySQL client?
    Thanks in advance for the fast reply!

    Regards!

Have another answer? Share your knowledge.