NS8 & NGINX .conf file

Hi all,

For Apache, in /etc/httpd/conf/httpd.conf, I can set AllowOverride to All so the directives in .htacess can All be applied.

# AllowOverride 
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:

I would like to add this line in nginx.conf:
AllowOverride All
so the directives in .htacess can All be applied for WordPress in webserver1 (9001).

Where is that nginx.conf for webserver1 (9001) ?

Michel-André

Hi all,

According to: How I migrated from Apache to Nginx – Donny Wals

What you might notice here is that the nginx configuration is a little bit longer and more detailed than the one for apache. This is because apache uses .htaccess files to set up global or per folder access and rewrite rules. Nginx doesn’t use these files and instead the configuration for that goes into your server configuration.

…instead the configuration for that goes into your server configuration…

I wonder what it means by server configuration ???

Michel-André

Hi @michelandre

Nginx sees itself as “server” app, in line with a long linux tradition.
As such it’s another way of saying the .conf file of nginx… :slight_smile:
The text itself also refers to a lengthier .conf file…

My 2 cents
Andy

I do not know if it is possible to easily override the config in the ns8 app: it much depends on the container configuration.

Let’s ask @stephdl !

Please take a read to the readme of ns8 module when you look informations we try to keep tracks to manual settings by cli or hidden features from UI

You could add a dyn-9001.custom to /home/webserver*/.config/state/conf.d/

AllowOverride is missing we need to add it as NFR

It is in this file that I added “index.php” and it worked.

Wihout it I have “Forbidden”

Michel-André

Salut Stéphane,

Does it means that AllowOverride is not used or that .htaccess is not use and that the directives for .htaccess should be included in vhost-nginx.conf ?

My goal for today was to study the original nginx.conf from https://docs.nginx.com.

Michel-André

Salut Stéphane,

The introduction of this file is very nice but there is not a single line explaining what this file does.
.
I think there should be at least a few lines describing the file and its purpose in every single file written! If not, good luck for the next programmer…

In another life, when I was programming in Perl, I wrote much more lines of description than lines of code. Even so, in this life if I read back, It’s diffical to follow on the first reading - imagine without a description.
It was even much worse with LISP - (Lost In Stupid Parentheses) the really but the most really worse one to follow what the writer is doing.

Michel-André

Yes I could agree but when you start to explain the code it is that the code is badly written

I can read as cristal clear what the code does

Salut Stéphane,

That is because you are young and a very good programmer with a very good memory.

Life is long and as it goes by, the ability and mainly the memory are weakening for everyone, no exception.

I am not sure that in 20 years you will see those codes as clearly as today.
Just wait and see with the next programmer.

Michel-André

I have tried to use the $“vhost”.custom , (thank you for thinking about it :slight_smile: )

apparently we can’t add directives to the “/” location ,

org:

location / {
        root   /usr/share/nginx/html/9004;
        index  index.html index.htm index.php;
        autoindex on;
    }

custom:

$shell> cat dyn-9004.custom
    location /. {
    add_before_body header.xhtml;
    add_after_body  footer.xhtml;
    }

Nginx complains about duplicate “blocks” etc,

My goal, is to serve an index_less folder , but I add to it some cosmetics …
(for a data mirror (Linux distros …))

if anyone has a suggestion, I’ll be more than grateful :slight_smile:

Did you try to add only this in the custom file

It works !

Thank you again

I have an analogue problem with a migrated wordpress site that doesn’t work anymore. It came from apache and I believe that I must add this to the nginx conf file :

location / {
    try_files $uri $uri/ /index.php?$args;
}

I tried to simply add try_files $uri $uri/ /index.php?$args; to dyn-9001.custom but it doesn’t work :

Output of nginx -T shows that the directive isn’t there

 # nginx -T | grep -A10 'server_name lebrass.be'
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
    server_name lebrass.be www.lebrass.be;

    include /etc/nginx/conf.d/dyn-9001[.]custom;

    location / {
        root   /usr/share/nginx/html/9001;
        index  index.html index.htm index.php;
        autoindex off;
    }

    # redirect server error pages to the static page /50x.html
/ # exit

however I see it a bit further but probably out of context :

}
# configuration file /etc/nginx/conf.d/dyn-9001.custom:
 try_files $uri $uri/ /index.php?$args;

How can I add this directive at the right place ?

@federico.ballarini you found it few time ago

i need to add this directive

try_files $uri /index.php?q=$uri&$args;

but it seems it's not working

2mo ago
the problem is that drupal is not working without url rewrite cause it returns always 404 not found
if u need in future for drupal you can create a dyn-9001.custom file and add this

rewrite ^(/.*\.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot|map))$ $1 break;

rewrite ^/$ /index.php last;
rewrite ^/index\.php$ /index.php break;
rewrite ^/(.+)$ /index.php?q=$1 last;

In my case (one year later ^^) I had to declare this in order for wordpress (migrated from apache) to work

# 1. Forcer le bon dossier racine pour éviter que Nginx ne se perde
root /usr/share/nginx/html/9003;

# 2. Servir directement les assets statiques et NE JAMAIS les envoyer vers index.php
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
    expires max;
    log_not_found off;
    access_log off;
    try_files $uri =404;
}

# 3. Règle de secours pour les permaliens WordPress (uniquement si ce n'est pas un fichier statique)
if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php last;
}