Skip to main content

Unable to stop nginx .conf files from being rebuilt frequently

Comments

10 comments

  • cPRex Jurassic Moderator

    Hey there!  There is no way to keep that file from rebuilding as that is a core function of cPanel.

    The include system is in addition to the main configuration file, not in place of it.  Can you add only the portions you want to change into the custom .conf file you've created?

    0
  • Carson Duling

    Hey! Thanks for the response. I could try doing that but I don't know how I would be able to only add specific portions if I get an error when I repeat the server_name directive in my custom file. 

    0
  • cPRex Jurassic Moderator

    Can you let me know the exactly values/variables you're trying to adjust in that configuration file?

    0
  • Carson Duling

    Of course. In the /etc/nginx/conf.d/users/{username}.conf file, I have a "location / { ... }" block with several nginx directives.

    In this block, I only want to change the "proxy_pass" value from what it currently is, which currently just points to my root domain's IP address, but I need it to point to an Docker container. 

    I also need to add a location block for socket.io ("location /socket.io/ { ... }"). So I add this to the end of the server block for the domain I need it for. 

    The rebuilding of this .conf file removes these directives. 

    Am I able to work around this by including a .conf file? 

    0
  • cPRex Jurassic Moderator

    Thanks for the additional details.  I spoke with some other technicians and they agreed that you should be able to create that without the "server_name" variable so you don't run into that conflict.  Does that not work for you?

    0
  • Carson Duling

    Do you mean I should be able to create a separate .conf file that I include using "include {file path}" to make these changes, and I would just exclude the server_name directive in that file? Or are you saying I should be able to make these changes directly in the .conf file I'm referencing? 

    0
  • cPRex Jurassic Moderator

    You would still want to use the custom file of either 

    /etc/nginx/conf.d/users/USER/include.conf

    for all domains under the user, or

    /etc/nginx/conf.d/users/USER/domain.tld/include.conf

    for the specific domain in question.

    0
  • Carson Duling

    Okay. It's starting to come together, but I'm not sure how to format the additional file correctly. 

    In the main file that keeps getting rebuilt, /etc/nginx/conf.d/users/{username}.conf, I already have the directive

    location / {
    proxy_pass {IP address}
    ... (several other directives)
    }

    In the second file, I add this same directive because I want to override the proxy_pass value:

    location / {
    proxy_pass {Docker container info}
    }

    When I run "nginx -t", I get the error, "nginx: [emerg] duplicate location "/" in /etc/nginx/conf.d/users/{username}/{domain name folder}/custom_config.conf:8", as if I'm unable to specify the "location /" block as it is repeated. 

    Is there a way to get around this error? How do I establish that I want to connect to this Docker container specifically when the user visits the root of the site? 

    Regarding the second location block, "location /socket.io/", which I also added to my custom config file, that doesn't seem to be giving any errors, so that might actually be set up to work. 

    0
  • cPRex Jurassic Moderator

    Thanks for the additional details - you can't override / like that, so I'm wondering if something like this would be better for your needs:

    https://support.cpanel.net/hc/en-us/articles/1500011220222-How-do-you-create-an-Apache-Reverse-Proxy-with-mod-proxy

    That would let you send traffic to the location of your choice without the need for customization to Nginx, and may result in a simpler configuration overall.

    0
  • Carson Duling

    Okay. Thanks for the help. 

    0

Please sign in to leave a comment.