Website redirect (Proxy) and subdomain rewrite

Discussion in 'Installation/Configuration' started by psopacua, May 14, 2024.

  1. psopacua

    psopacua New Member

    Hello everyone,
    In ISPConfig i have a website configured with a proxy redirect because my main website is served as a NextJS project on my server.

    The redirect configuration of my website is as follow
    Tab: Redirect
    Redirect type: Proxy
    Redirect path: http://127.0.0.1:3000
    SEO Redirect: No redirect

    I have also added a subdomain with "last" rule because i want to serve another webapplication under "/web/makelaar" the subdomain configurations:
    Host: makelaar
    Domain: domain.ltd
    Redirect Type: last
    Redirect path: /makelaar/
    Don't add to Let's Encrypt certificate: Unchecked
    Active: Checked

    Now if i go to https://makelaar.domain.ltd it always gets redirected to https://makelaar.domain.ltd/makelaar and i am getting the 404 error page served from the proxy instead of the webapplication in /web/makelaar.

    nginx configuration:

    Code:
    server {
            listen *:80;
            listen [::]:80;
            listen *:443 ssl http2;
    
        ssl_protocols TLSv1.3 TLSv1.2;
            listen [::]:443 ssl http2;
            ssl_certificate /var/www/clients/client1/web4/ssl/domain.ltd-le.crt;
            ssl_certificate_key /var/www/clients/client1/web4/ssl/domain.ltd-le.key;
    
            server_name domain.ltd www.domain.ltd makelaar.domain.ltd;
    
            root   /var/www/domain.ltd/web/;
            disable_symlinks if_not_owner from=$document_root;
    
            if ($http_host = "makelaar.domain.ltd") {
                rewrite ^(?!/(makelaar|stats|error|\.well-known/acme-challenge))/(.*)$ /makelaar/$2 last;
            }
    
            location ^~ /.well-known/acme-challenge/ {
                access_log off;
                log_not_found off;
                root /usr/local/ispconfig/interface/acme/;
                autoindex off;
                index index.html;
                try_files $uri $uri/ =404;
            }
    
            location / {
                proxy_pass http://127.0.0.1:3000/;
    
            }
    }
    
    server {
            listen *:80;
            listen [::]:80;
    
    
            listen *:443 ssl http2;
            listen [::]:443 ssl http2;
            ssl_certificate /var/www/clients/client1/web4/ssl/domain.ltd-le.crt;
            ssl_certificate_key /var/www/clients/client1/web4/ssl/domain.ltd-le.key;
    
            server_name domain2.ltd *.domain2.ltd;
    
            location ^~ /.well-known/acme-challenge/ {
                access_log off;
                log_not_found off;
                root /usr/local/ispconfig/interface/acme/;
                autoindex off;
                index index.html;
                try_files $uri $uri/ =404;
            }
            location / {
                rewrite ^ https://www.domain.ltd$request_uri? permanent;
            }
    Someone who can assist me further to make it possible to serve my NextJS application on the main domain and the subfolder on the subdomain?

    Thanks in advance!
     
    Last edited: May 14, 2024
  2. psopacua

    psopacua New Member

    Hi all,

    after trying a lot of things and nothing worked and heavily searching on the web i came on the following post of this forum:
    https://forum.howtoforge.com/threads/subdomain-to-internal-port-with-nginx.79952/

    Based on this i have added the subdomain site as a website to ISPConfig. This way it makes it possible for me to use the subdomains without any problems.

    If someone knowns a better solution i would love to hear it!

    Thanks in advance.
     
  3. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    The "issue" is, if the subdomain is configured without beeing its own vhost, there's just a redirect
    happening.
    But then the configuration says, regardless, anything matching / shall be proxied.

    If the configuration is seperated this does not happen.

    Another way would be to use the options tab and configure the vhost yourself.
    Then you could add a
    location /bar { ... }
    and instruct nginx to stop here or if the request is not for /bar go further and do the
    location / { proxy ]

    I think the option you chose is less work :)
     
    ahrasis and psopacua like this.
  4. psopacua

    psopacua New Member

    Interesting, for sure i am going to figure this out the way you tell me.
    I known my way is less work but i prefer 1 website per domain and its configurations.

    Thank you very much!
     

Share This Page