-4

I am trying to setup multiple https websites via apache or nginx virtualhost but i noticed i have to append the port to the end of the IP address to view the https of websites that uses non default 443 ssl port

Is it possible to have multiple https websites on same server using different ports? If yes then how can one do this without needing to append the non default port at the end

What i have tried

# Ensure that Apache listens on port 80 and all ssl ports
Listen 80 
Listen 443
Listen 543


# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
NameVirtualHost *:443
NameVirtualHost *:543

<VirtualHost 192.168.101.44:443>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here

</VirtualHost>

<VirtualHost 192.168.101.54:543>
DocumentRoot /www/example2
ServerName www.example2.org

# Other directives here

</VirtualHost>

in that order and will be be able to reach the websites on https://www.example1.com and https://www.example2.org respectively

Is this possible? Apache? Nginx? I use both webservers so will like to know if it can work work with either or both. I can edit the question to be clearer if needed.

Thanks

  • 1
    You are asking for a contradiction! If you want to use a port other than 443, you must specify it. If you don't want to specify a port, you must use port 443. Why do you want to use different ports anyway? You can certainly have as many sites as you want on port 443. – Michael Hampton Feb 16 '16 at 5:34
  • Oh i can? so can you specify the correct config for such? or point to url to check that? thanks...you can post that as an answer so i can choose as solution to my question..thanks – uberrebu Feb 16 '16 at 5:40
  • also by the way i will also like to know of a way to use different ports as well just in case 443 is used by another service for some reason..thanks – uberrebu Feb 16 '16 at 5:41
  • Having multiple TLS servers on one port works because of something called SNI. – Parthian Shot Feb 16 '16 at 14:57
2

You can have as many sites as you like served from one server, with one IP address, and each domain can be listening on ports 80 and 443. So example.com can listen on 80/443, example1.com can listen on 80/443, etc.

In nginx you just define multiple servers, as below

server {
  server_name www.example.com;
  listen 80;
  listen 12345;
  listen 443 ssl;

  location / {
    # whatever
  }
}

server {
  server_name www.example1.com;
  listen 80;
  listen 443 ssl;

  location / {
    # whatever
  }
}

# This server simply redirects the requested to the https version of the page
server {
  listen 80;
  server_name example.com;
  return 301 https://www.example.com$request_uri;
}

You may be better forwarding from 80 to 443 so everything is secure. I have a pretty thorough set of config files in this tutorial, and plenty on nginx in general.

Note, someone suggested an edit direct to another part of my tutorial. I linked direct to that page as it has the table of contents for the whole series tutorial, along with the nginx config files you can download.

  • 1
    Remember that if is evil. You should have the port 80 redirects in separate server blocks. – Michael Hampton Feb 16 '16 at 5:41
  • what about using different posts as well? will like to know that..you can past as alternative/additional solution under current..thanks! – uberrebu Feb 16 '16 at 5:45
  • @MichaelHampton what do you mean port 80 redirect in separate server blocks? you mean have separate vhost for port 80 and redirect from that vhost? – uberrebu Feb 16 '16 at 5:46
  • @tim so i can use 1 single IP address for these multiple websites? thats the key here using one single ipv4 address for these multiple ssl sites – uberrebu Feb 16 '16 at 5:47
  • Yes I have 10 domains on one IP, big shared hosting providers will put hundreds on an IP. I've updated to show how to listen to other ports. – Tim Feb 16 '16 at 6:34
0

Is it possible to have multiple https websites on same server using different ports?

Yes, name based virtual hosting is the broad name for the technology. There are many examples of this all over SF and the wider internet.

If yes then how can one do this without needing to append the non default port at the end

You can't. The standards define port 80 for HTTP and port 443 for HTTPS so you don't need to supply them and your standards compatible tool knows where to connect based upon the scheme.

If you are using a non standard port then you have to supply it.

  • ok can i have multiple websites use https on port 443 all on same IP address? – uberrebu Feb 16 '16 at 6:40
  • 1
    Please, do us all a favour and go read what we've already written some some documentation an educate yourself properly rather than trying to do something by soundbites. @Tim has already demonstrated this is possible, yeesh. – Iain Feb 16 '16 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.