Subdomain to internal port with nginx

Discussion in 'General' started by effoo, Sep 9, 2018.

  1. effoo

    effoo New Member

    Hi everybody,

    I am really confused by now because of the following:
    I am trying to route all requests for a certain subdomain (cloud.domain.tld), which was set up in ISPConfig running on nginx, to an internal Apache server running on port 8082. Technically I want to proxy cloud.domain.tld through nginx to localhost:8082 but configure it with ISPConfig.

    The Apache server is set up to listen to all request on said port. The problem here is the configuration of the nginx through ISPConfig. Because of this setup I can barely find any helping information on google (or I am too stupid).
    So, I really hope you can shed light on this topic.

    I've tried to change the domain's nginx directives in the Options panel but it seems like you cannot add the following part.
    (Probably because it's nesting 'server{ server{} }', right?)
    Code:
    server {
            listen *:80;
            listen *:443 ssl;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_certificate /var/www/clients/client1/...;
            ssl_certificate_key /var/www/clients/client1/...;
    
            server_name cloud.domain.tld;
    
            location / {
                    proxy_set_header X-Real-IP  $remote_addr;
                    proxy_set_header X-Forwarded-For $remote_addr;
                    proxy_set_header Host $host;
                    proxy_pass http://127.0.0.1:8082;
            }
            location ~ /\.ht {
                    deny all;
            }
    }
    Setting the subdomain to a redirect seems weird and I don't really know how to redirect it to an internal port through ISPConfig.
    Editing the domain.vhost directly and bypass ISPConfig would be possible, I think, but I cannot imagine that this would be a very healthy way and intended at all.

    Using the nginx Directives in ISPConfig to do all this would be very neat. I am grateful for any help.
    Thanks!
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    You are trying to add a vhost inside a vhost and this can not work. Try adding just the proxy part in the nginx directives field:

    Code:
    location / {
                    proxy_set_header X-Real-IP  $remote_addr;
                    proxy_set_header X-Forwarded-For $remote_addr;
                    proxy_set_header Host $host;
                    proxy_pass http://127.0.0.1:8082;
            }
     
  3. effoo

    effoo New Member

    Thank you for your answer. I thought so.
    But your solution routes ALL the requests that go to domain.tld to the proxy or did I get that wrong?
    I want to re-route just the requests that go to ONE subdomain to the local server.

    E.g.
    subdomain1.domain.tld --> localhost:8082 front-end
    subdomain2.domain.tld --> nginx front-end
    [...]
    domain.tld --> nginx front-end

    ISPConfig won't let me put in nginx directives for subdomains...
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Create a new website where you enter 'cloud.domain.tld' in the domain field, then switch to the options tab of that newly created website and enter the nginx directives.
     
  5. effoo

    effoo New Member

    Oh...I did not think about this at all.
    Thank you for quick support.
     

Share This Page