How to Deal with 'nginx.conf' file

Hello Hestia Team and Other Hestians.

Actually, I know this is not good to ask for help here regarding anything else except HestiaCP.
But I tried almost all possible ways and not able to solve the issue.
What I have to do is…

I have a ‘nginx.conf’ file in /home/{user}/web/{web}/public_html/.nginx.conf. I have to include this with nginx.conf for the same user and website.

I tried to add it as "include /home/{user}/web/{web_address}/public_html/.nginx.conf"

But When I restart Nginx with the new Configuration, it give error and cannot be started…

The Software I am talking about is Flarum Forum Software…
Guide I’m following : Installation | Flarum Documentation

Am I not following steps correctly or there is other way to do so.

Thanks in Advance.

Remove the dot symbol before nginx.conf. For security reasons, it is better not to store the nginx configuration file in the public_html folder, but to move it to a higher level.

I would make a new template with the changes made in the default.tpl / stpl saves an include

1 Like
  1. Where did you try to insert that include statement ?

  2. Also check journalctl -u nginx after restarting it and look for any error messages

#=======================================================================#
# Default Web Domain Template                                           #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
#=======================================================================#

server {
    listen      xxx.xxx.xxx.xxx:443 ssl http2;
    server_name sub.domain.com ;
    root        /home/user/web/sub.domain.com/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/sub.domain.com.log combined;
    access_log  /var/log/nginx/domains/sub.domain.com.bytes bytes;
    error_log   /var/log/nginx/domains/sub.domain.com.error.log error;

    ssl_certificate      /home/user/conf/web/sub.domain.com/ssl/sub.domain.com.pem;
    ssl_certificate_key  /home/user/conf/web/sub.domain.com/ssl/sub.domain.com.key;
    ssl_stapling on;
    ssl_stapling_verify on;

    include /home/user/conf/web/sub.domain.com/nginx.hsts.conf*;

I TRIED IT HERE AND BELOW ALSO

    location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
            fastcgi_hide_header "Set-Cookie";
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    unix:/run/php/php7.4-fpm-sub.domain.com.sock;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    location /error/ {
        alias   /home/user/web/sub.domain.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   /home/user/web/sub.domain.com/stats/;
        include /home/user/web/sub.domain.com/stats/auth.conf*;

    }
	
    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /home/user/conf/web/sub.domain.com/nginx.ssl.conf_*;

HERE ALSO

}

TRIED IN BOTH NGINX.CONF and NGINX.SSL.CONF

as you can see, the conf files already hold an include directive that allows for custom configs. you just need to put it in /home/user/conf/web/sub.domain.com/ and name it nginx.ssl.conf_something so it matches the include.

after that run nginx -t or try to restart and check journalctl output if it fails.
depending from whereever you copied whatever is in that conf file you most likely need to adjust it to your installation.

use your administrations skills and linux powers for that! good luck.

thanks Everyone for such response, actually there is some conflict between default nginx.conf and provided .nginx.conf file…

I almost clear all conflicts and make nginx working but still not get the exact performance what I want so just revert to Apache + Nginx.

that nginx vs apache2 performance discussion is by far overrated IMHO. maybe, if you run on a small system and have to be careful with ressources and such, maybe then it can help to get rid of apache in between. but most users will put in whatever plugin for everything in wordpress (just an example) anyway without thinking about performance at all and then try to solve performance issues on the other end…

don’t get me wrong, I am not denying that nginx might offer better performance but I also believe that the efforts needed to adjust configs and such are often not worth a rather small gain. technically apache2 handling (.htaccess) things like rewrites and headers and the connection to php is just another man in the middle - which might be avoidable but not neccessarily consumes as much performance as one might think.

so, happy to see that you a) where able to fix the nginx conflicts :+1:t2: and b) decided that it’s not worth it and instead just using what’s proven to work for your framework :wink:

Exactly @falzo Sir,

I believe that nginx perform better, but those minor difference may lead to headache. I agree with you that Apache + Nginx is best combination for everything (almost).

But this give another experience why .htaccess far better than rules defined in nginx.conf.

BTW, Thanks for your help, Appreciated :slight_smile:

1 Like