Nginx several websites, different domains

  • Nginx is able to run several servers. So far I've put 2 WordPress sites on the same server and they run well over LAN. Something like 192.168.1.5:80 and 192.168.1.5:81. On a router level external port 80 is forwarded to both: 80 and 81 of the same server.


    The problem is domains - how to feed to Nginx that on request http://www.domain1.com it has to bring up website1, but on www.domain2. - website2 ???


    On Synology devices that is done via Virtual Hosts. I found that on Nginx something similar is related to
    etc/nginx/sites-available/openmediavault-nginx file. At least Nginx writes data of both websites into this file. Now the file of mine looks like this:



    But right now Nginx brings up only first (the oldest) site on both domain requests. What should I do to have it working right?

  • named-based allows you to run sites on the same port. I have five domains running on port 80 on a server.

    omv 5.6.2 usul | 64 bit | 5.4 proxmox kernel | omvextrasorg 5.5.3
    omv-extras.org plugins source code and issue tracker - github


    Please read this before posting a question.
    Please don't PM for support... Too many PMs!

  • I know you can run same hostnames with different port.
    How you can run with the same port?

    Install some servers. Switch their "Host Type" to Name-based.

    Call them
    server1.lan, server2.lan ...
    ...and make shure, your name-resolution delivers your server's IP adress for these names.

  • I didn't know that.
    I have five hosts, and my NextCloud is currently auto redirect from HTTP (80) to HTTPS (443), how would the server know which host it needs to redirect to?
    Will network congestion effect the sites performance?

    OMV v5.0
    Asus Z97-A/3.1; i3-4370
    32GB RAM Corsair Vengeance Pro

  • Each http-request includes the destination adress ("http://www.myserver.lan").
    This is used to direct the request to the desired service.


    I don't think that your nextcloud redirect will have a problem with this.
    This method is also commonly used by shared hosters.


    And has nothing to do with network congestion. :D

  • Wooow, how did I miss that.....


    Thanks a lot, gentlemen (and ladies, if any :))


    Everything works as it should out of the box and without any fancy stuff.


    Thanks a lot!

  • i'm stupid?!?
    i will make two sides with the namebased option. but it have no efect.
    my configure like these:
    omv http port 880
    omv https port 50443
    webpage one with namebased server1.lan on http 80 and defould server otion for the https port 443
    webpage two with namebased server2.lan on http 80 and for the https port 443



    When i will go with my browser to server1.lan or server2.lan i have the error:
    This site can’t be reached
    server1.lan ’s server DNS address could not be found.




    what’s wrong?

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

  • You have to point your DNS to your OMV server.This can be done in your routers host-file, if possible, or on your local hosts file.


    For example:
    192.168.1.10 server1.lan
    192.168.1.10 server2.lan

    sorry, i don't know whot you meen. Can you explain it a litle bit more?

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

  • Deutsch ist gut!


    Im Browser gibst du den Namen deines Servers ein.
    myserver1.lan


    Der Browser muss das dann allerdings in eine IP Adresse "auflösen", um ein TCP Verbindung aufbauen zu können.


    Das Auflösen passiert über DNS (und/oder lokale "hosts" Datei).
    Hast du Windows?
    Dann kannst du das in einem CMD Fenster testen (nslookup fragt den DNS Server ab):


    C:\nslookup myserver1.lan


    Wenn der DNS Server den Eintrag nicht kennt, muss man da nachhelfen.
    Entweder den DNS Server (i.A. der Router) entsprechend konfigurieren (wenn es geht), oder behelfsweise die lokale "hosts" Datei ergänzen.

  • okay, danke erstmal für deine Antwort.


    ich habe nur linux systeme. ich habe schon probiert, mit ping eine Verbindung zu dem Namen zu testen. Ich bekomme nur die Meldung das er nicht bekannt ist.


    Entweder den DNS Server (i.A. der Router) entsprechend konfigurieren (wenn es geht), oder behelfsweise die lokale "hosts" Datei ergänzen.

    Ich habe eine Fritzbox. ich wüsste nicht wo ich da diese Sache machen sollte. Und wie sähe das in der hosts Datei kongret aus? bzw wo finde ich diese?

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

  • Ansonsten in der Datei
    /etc/hosts
    hinzufügen:
    192.168.1.10 server1.lan
    192.168.1.10 server2.lan

    funktioniert leider trotzdem nicht. ich auch mal neu gestartet.

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

  • Die Seiten sind trotzdem nicht erreichbar d.h. weiterhin server1.lan keine Verbindung, weder mit Browser noch mit ping.
    in meiner /etc/hosts habe ich folgendes

    Code
    127.0.0.1 localhost
    127.0.1.1 omvhost
    192.168.168.24 server1.lan
    192.168.168.24 server2.lan
    ...
    ein paar ipv6 angaben

    sieht das bei dir ähnlich aus?

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

  • ahhh sooo.
    Jetzt gehts.
    Danke!

    omv 5.x | 64 bit | omvextrasorg 5.x | kernel 5.4
    used plugins: omv-extras | portainer | rsnapshot | antivirus
    used container: portainer/portainer | linuxserver/nextcloud | linuxserver/letsencrypt | linuxserver/mariadb | jellyfin/jellyfin | doliana/logitech-media-server | v2tec/watchtower | instrumentisto/coturn

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!