Nginx several websites, different domains

    • OMV 2.x
    • Resolved

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • 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 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:

      Source Code

      1. server {
      2. listen [::]:80 ipv6only=off;
      3. set $root_path "/media/d1fe4050-e804-4831-b6b5-e8903ffe2b53/web/website1/";
      4. root $root_path;
      5. index index.php;
      6. set $socket "unix:/var/run/fpm-7f79544d-f5b0-45af-9f2c-3a6a4fb79ffe.sock";
      7. location ~ \.php$ {
      8. fastcgi_split_path_info ^(.+\.php)(/.+)$;
      9. fastcgi_pass $socket;
      10. fastcgi_index index.php;
      11. include fastcgi_params;
      12. }
      13. access_log /var/log/nginx/3204618d-bba5-487b-a595-e2ef8fedb39a-access.log;
      14. error_log /var/log/nginx/3204618d-bba5-487b-a595-e2ef8fedb39a-error.log;
      15. large_client_header_buffers 4 8k;
      16. }
      17. server {
      18. listen [::]:81 ipv6only=off;
      19. set $root_path "/media/d1fe4050-e804-4831-b6b5-e8903ffe2b53/web/website2/";
      20. root $root_path;
      21. index index.php;
      22. set $socket "unix:/var/run/fpm-a65bc8cd-588c-4b74-82f9-648ae0ec6646.sock";
      23. location ~ \.php$ {
      24. fastcgi_split_path_info ^(.+\.php)(/.+)$;
      25. fastcgi_pass $socket;
      26. fastcgi_index index.php;
      27. include fastcgi_params;
      28. }
      29. access_log /var/log/nginx/85d8d84e-6c5f-43b4-b74e-2f8ff6435006-access.log;
      30. error_log /var/log/nginx/85d8d84e-6c5f-43b4-b74e-2f8ff6435006-error.log;
      31. large_client_header_buffers 4 8k;
      32. }
      Display All

      But right now Nginx brings up only first (the oldest) site on both domain requests. What should I do to have it working right?
    • 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
    • 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 4.0.15 | 64 bit | omvextrasorg 4.1.2 | kernel 4.13
      used plugins: nginx | mysql | docker-gui | flashmemory |rsnapshot | antivirus | apt tool | letsEncrypt |
      used other: netxtcloud | logitechmediaserver | emby
    • Enra wrote:

      happyreacer wrote:

      server1.lan ’s server DNS address could not be found.
      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 4.0.15 | 64 bit | omvextrasorg 4.1.2 | kernel 4.13
      used plugins: nginx | mysql | docker-gui | flashmemory |rsnapshot | antivirus | apt tool | letsEncrypt |
      used other: netxtcloud | logitechmediaserver | emby
    • 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.

      Enra wrote:

      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 4.0.15 | 64 bit | omvextrasorg 4.1.2 | kernel 4.13
      used plugins: nginx | mysql | docker-gui | flashmemory |rsnapshot | antivirus | apt tool | letsEncrypt |
      used other: netxtcloud | logitechmediaserver | emby
    • Enra wrote:

      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 4.0.15 | 64 bit | omvextrasorg 4.1.2 | kernel 4.13
      used plugins: nginx | mysql | docker-gui | flashmemory |rsnapshot | antivirus | apt tool | letsEncrypt |
      used other: netxtcloud | logitechmediaserver | emby
    • 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

      Source Code

      1. 127.0.0.1 localhost
      2. 127.0.1.1 omvhost
      3. 192.168.168.24 server1.lan
      4. 192.168.168.24 server2.lan
      5. ...
      6. ein paar ipv6 angaben
      sieht das bei dir ähnlich aus?
      omv 4.0.15 | 64 bit | omvextrasorg 4.1.2 | kernel 4.13
      used plugins: nginx | mysql | docker-gui | flashmemory |rsnapshot | antivirus | apt tool | letsEncrypt |
      used other: netxtcloud | logitechmediaserver | emby