Customizing NGINX configuration
Hello,
I have installed NGINX as a reverse proxy by using the NGINX Manager in WHM. I need to override the NGINX configuration for a specific server block for a specific domain as described in the below article:
https://docs.cpanel.net/knowledge-base/nginx/customize-reverse-proxy-nginx-configurations/
I created a .conf file in the following directory:
/etc/nginx/conf.d/users/username/domainname/
with the below content:
location / {
proxy_pass http://127.0.0.1:6081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
Afterwards, I ran the below command so as to check the validity of the configuration and I got the following error:
# nginx -t
nginx: [emerg] duplicate location "/" in /etc/nginx/conf.d/users/myuser/my.example.com/my-conf.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed
-
Hey there! I wouldn't expect the user block to be able to override the / location, as that would apply to all users on the system. Can you try narrowing that path down for the user a bit and see if that passes the test?
0 -
My main configuration file "/etc/nginx/conf.d/users/myuser.conf", that is automatically generated, includes the below block:
location / {
proxy_cache $CPANEL_PROXY_CACHE;
proxy_no_cache $CPANEL_SKIP_PROXY_CACHING;
proxy_cache_bypass $CPANEL_SKIP_PROXY_CACHING;
proxy_cache_valid 200 12d;
proxy_cache_valid 301 12d;
proxy_cache_valid 302 12d;
proxy_cache_use_stale error timeout http_429 http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_revalidate on;
proxy_cache_min_uses 1;
proxy_cache_lock off;
include conf.d/includes-optional/cpanel-proxy.conf;
proxy_pass $CPANEL_APACHE_PROXY_PASS;
}How can I override the above directives with the following ones?
location / {
proxy_pass http://127.0.0.1:6081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}0 -
Thanks for the additional details. It is my understanding that this isn't possible - in order to change the main block for a user you would have to edit and customize the nginx template, but that would make the change globally for all users.
0
Please sign in to leave a comment.
Comments
3 comments