custom HTTPD/Nginx Configuration

XATRIX

New member
Joined
Sep 14, 2016
Messages
2
Hi, i have a trouble. I need to add a custom "location" block to one of my domains. I don't want to make a copy of a template, because of i need it only for the certain domain. Also, i need it permanent so, i decided to use this file for: /usr/local/directadmin/data/users/$USER/domains/$DOMAIN.cust_nginx


What i currently have:

Code:
# Auto generated nginx config file by DirectAdmin version 1.50.1
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to their website

# For global config changes that affect all Users, see this guide:
# http://help.directadmin.com/item.php?id=558
# For local config changes that only affect one User, see this guide:
# http://help.directadmin.com/item.php?id=3


server
{
        listen 78.155.221.251:80;
        server_name somedomain.com www.somedomain.com ;
        access_log /var/log/nginx/domains/somedomain.com.log;
        access_log /var/log/nginx/domains/somedomain.com.bytes bytes;
        error_log /var/log/nginx/domains/somedomain.com.error.log;
        root /home/someuser/domains/somedomain.com/public_html/current/frontend/web;
        index index.php index.html index.htm;
        include /usr/local/directadmin/data/users/someuser/nginx_php.conf;
        location /
        {
                # access_log off;
                proxy_buffering off;
                proxy_pass http://78.155.221.251:8080;
                proxy_set_header X-Client-IP      $remote_addr;
                proxy_set_header X-Accel-Internal /nginx_static_files;
                proxy_set_header Host             $host;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
        location /nginx_static_files/
        {
                # access_log  /var/log/nginx/access_log_proxy;
                alias       /home/someuser/domains/somedomain.com/public_html/current/frontend/web/;
                internal;
        }
        include /etc/nginx/webapps.conf;
}

What i want it to be:

Code:
# Auto generated nginx config file by DirectAdmin version 1.50.1
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to their website

# For global config changes that affect all Users, see this guide:
# http://help.directadmin.com/item.php?id=558
# For local config changes that only affect one User, see this guide:
# http://help.directadmin.com/item.php?id=3


server
{
        listen 78.155.221.251:80;
        server_name somedomain.com www.somedomain.com ;
        access_log /var/log/nginx/domains/somedomain.com.log;
        access_log /var/log/nginx/domains/somedomain.com.bytes bytes;
        error_log /var/log/nginx/domains/somedomain.com.error.log;
        root /home/someuser/domains/somedomain.com/public_html/current/frontend/web;
        index index.php index.html index.htm;
        include /usr/local/directadmin/data/users/someuser/nginx_php.conf;

        location ~* \.(jpg|jpeg|gif|png|swf|tiff|swf|flv)$ {
                expires 4M;
                add_header Cache-Control public;
        }

        location /
        {
                # access_log off;
                proxy_buffering off;
                proxy_pass http://78.155.221.251:8080;
                proxy_set_header X-Client-IP      $remote_addr;
                proxy_set_header X-Accel-Internal /nginx_static_files;
                proxy_set_header Host             $host;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
        location /nginx_static_files/
        {
                # access_log  /var/log/nginx/access_log_proxy;
                alias       /home/someuser/domains/somedomain.com/public_html/current/frontend/web/;
                internal;
        }
        include /etc/nginx/webapps.conf;
}




Code:
location ~* \.(jpg|jpeg|gif|png|swf|tiff|swf|flv)$ {
      expires 4M;
      add_header Cache-Control public;
}
 
Yes, it works! Thanks a lot! But i have another one question. I'd like to put/change some more directives like (proxy_cache, proxy_cache_ignore...) to location / {}, any idea how to ?

Code:
location /
        {
                # access_log off;
                proxy_buffering off;
                proxy_pass http://78.155.221.251:8080;
                proxy_set_header X-Client-IP      $remote_addr;
                proxy_set_header X-Accel-Internal /nginx_static_files;
                proxy_set_header Host             $host;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
 
You cannot change those unless you change the template (not sure if you add another location / section if that override the previous, it may be worth a try.

For the template:
Code:
mkdir -p /usr/local/directadmin/data/templates/custom/
cp /usr/local/directadmin/data/templates/nginx_server.conf /usr/local/directadmin/data/templates/custom/nginx_server.conf

Than edit the template /usr/local/directadmin/data/templates/custom/nginx_server.conf
And run:
Code:
echo "action=rewrite&value=nginx" >> /usr/local/directadmin/data/task.queue && /usr/local/directadmin/dataskq

Best regards
 
Hello,

Yes, it works! Thanks a lot! But i have another one question. I'd like to put/change some more directives like (proxy_cache, proxy_cache_ignore...) to location / {}, any idea how to ?

Use |CUSTOM2| section for this in Directadmin. The proxy cache's directives can be easily inserted with it. Just take care of proxy_buffering ;)
 
In DA, Admin level, Custom HTTP Configuration, select the domain (the nginx template) and add your require code to CUSTOM3 value.

Regards

sorry to bump old post but wanted to say thanks, was looking for this exact setting to raise client_max_body_size to allow large video file uploads, seems to be working very well
 
Back
Top