DirectAdmin through Nginx reverse proxy and problem with webapps

Beherit

Verified User
Joined
Dec 2, 2019
Messages
35
Following this tutorial, I configured to access DirectAdmin on port 443 by editing etc/nginx/nginx-includes.conf file:
Code:
server {
        listen 1.2.3.4:443 ssl http2;
        listen [1:2:3:4:0:0:0:5]:443 ssl http2;
        server_name cp.domain.tld;

        ssl_certificate /usr/local/directadmin/data/users/admin/domains/domain.tld.cert.combined;
        ssl_certificate_key /usr/local/directadmin/data/users/admin/domains/domain.tld.key;
        
        include /etc/nginx/webapps.ssl.conf;
        
        location / {
                proxy_pass "https://server.domain.tld:2222/";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect "https://cp.domain.tld:2222/" "https://cp.domain.tld/";
        }
}
Control panel works perfect without any problems but problem is with webapps - static files like JS and CSS e.g. from Roundcube doesn't loads and gives error 404. I using nginx+apache. What should I do to fix that issue?
 
Try to add

Code:
server {
        listen 1.2.3.4:443 ssl http2;
        listen [1:2:3:4:0:0:0:5]:443 ssl http2;
        server_name cp.domain.tld  www.cp.domain.tld;

        
       access_log /var/log/nginx/domains/cp.domain.tld.log;
       access_log /var/log/nginx/domains/cp.domain.tld.bytes bytes;
       error_log /var/log/nginx/domains/cp.domain.tld.error.log;

        root /home/admin/domains/cp.domain.tld/private_html;
        index index.php index.html index.htm;

        ssl_certificate /usr/local/directadmin/data/users/admin/domains/domain.tld.cert.combined;
        ssl_certificate_key /usr/local/directadmin/data/users/admin/domains/domain.tld.key;
       
        
       include /usr/local/directadmin/data/users/admin/nginx_php.conf;
        include /etc/nginx/webapps.ssl.conf;
       
        location / {
                proxy_pass "https://server.domain.tld:2222/";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect "https://cp.domain.tld:2222/" "https://cp.domain.tld/";
        }
       
        location / {
        try_files $uri $uri/ /index.php?$args;
}
}

add root location, error response, and try files
Hope that help
 
Last edited:
How is it supposed to work if there are two definition of "location /"? :P Problem disappearing only when I removing "proxy_set_header X-Accel-Internal" from webapps.ssl.conf.
 
How is it supposed to work if there are two definition of "location /"? :p Problem disappearing only when I removing "proxy_set_header X-Accel-Internal" from webapps.ssl.conf.
Normally webapps (ie, phpmyadmin, roundcube, etc) will work automatically without set any rule.

If just the problem solved the easy way add customization at https config at DA admin panel. For two location for website deployed, create custom rule for each sub domain.


Add custum rule, I often add in custom 4
for example for sub pxl.domain.ltd
Code:
|*if SUB="plx"|
   ....the custom rule...
|*endif|

for to point webapps in other sub domain or directory, you can create location rule in that subdomain virtual host to point the webapps to proxy port 2222

Code:
       location / {
                proxy_pass "https://server.domain.tld:2222/";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_redirect "https://cp.domain.tld:2222/" "https://cp.domain.tld/";
        }

Hope that help
 
Last edited:
there have something went wrong with location block ( Regex Rule ) of "X-Accel-internal"

This's how I debug problem

even try printing $uri , it show correct url and it should correct regex, but I don't know why wrong regex ;-(

maybe cause by {root} inside sub location
 
For two location for website deployed, create custom rule for each sub domain.
In my configuration "cp.domain.tld" is not a subdomain added in DirectAdmin, I just added DNS records, this is no normal subdomain.
 
Back
Top