How to get nginx.conf include directive to ignore .bak files - nginx

How do I get the include directory for ngnix conf files to ignore *.bak?
I back up my configuration files, for example default -> default.bak. I want to include /etc/nginx/sites-enabled/default but not /etc/nginx/sites-enabled/default.bak in nginx.conf. How do I do this?

I would recommend changing default to default.conf or another extension if possible , then include can properly differentiate from config and bak.
http {
include /etc/nginx/sites-enabled/*.conf;
}

Related

Static not existing though being declared in nginx default config

I'm trying to get my static files accessible so that I can load them with Flask.
ex: https://example.com/static/render.css
I've included this in the https part of my site:
location /static/ {
autoindex on;
alias /root/site/static;
}
But it just returns a 403 always.
The directory is correct and all, I've also ran the chown -R /root/site/static/ command. Idk what's the issue.
Nginx is definitely doing something with the data though, as all other extensions just reply a badgateway.
I decided to just write my CSS inline.

How to conf nginx worker_connections with cf buildpack staticfile

I'm using the CF buildpack staticfile and added the Custom Location feature to conf my Special Location (documented here).
Now I want to increase the number of worker_processes and/or worker_connections used by Nginx. This is possible adding a nginx.conf file but this is deprecated and I would like to stick with the new pattern to only specify the conf that differs from the defaults.
Is there any way to specify worker_connections in a conf file that will be use when building the nginx.conf?
You cannot set worker_processes or work_connections in this manner for two reasons.
These two properties cannot be set in a location block (see https://nginx.org/en/docs/ngx_core_module.html#worker_processes and https://nginx.org/en/docs/ngx_core_module.html#worker_connections).
The configuration mechanism you're using will include your custom file into the single location block that is in the generated config file.
Thus it's not possible to set those two values using this manner, because neither can be set in a location block and that is the only place you can inject configuration, the location block using this configuration mechanism.
If you need to customize these settings, I would suggest that you use the nginx-buildpack instead and just provide a full custom nginx.conf file.
If you like, you can run once using the staticfile buildpack, cf ssh into the container, copy out the generated config file for your app, then switch to the nginx-buildpack and use the copied config file. That will give you a base configuration file, you can then edit as you need and get something similar.

Which prefix does NGINX use for "include"?

While I'm compiling NGINX, I get this message:
nginx path prefix: "/tmp/app"
nginx binary file: "/tmp/app/progs/nginx/sbin/nginx"
nginx configuration prefix: "/tmp/app/progs"
nginx configuration file: "/tmp/app/progs/nginx.conf"
Does NGINX use the path prefix or the configuration prefix for include directives in nginx.conf?
The documentation suggests that it's the "prefix path":
–prefix=path defines a directory that will keep server files. This same directory will also be used for all relative paths set by configure (except for paths to libraries sources) and in the nginx.conf configuration file. It is set to the /usr/local/nginx directory by default.
By contrast:
–conf-path=path sets the name of an nginx.conf configuration file. If needs be, NGINX can always be started with a different configuration file, by specifying it in the command-line parameter -c file. By default the file is named prefix/conf/nginx.conf.
However, this is a documentation bug, and your include paths will in fact be relative to the "config path".

Which nginx-config file is enabled, /etc/nginx/conf.d/default.conf or /etc/nginx/nginx.conf?

There are two config files around, /etc/nginx/conf.d/default.conf
and /etc/nginx/nginx.conf, but which one is enabled?
I am running CentOS6.4 and nginx/1.0.15.
Technically, nginx.conf is all that matters, if you define every thing inside there it would still work, but to keep things organized, they use include, somewhere at the end of nginx.conf you'll see include /etc/nginx/conf.d/* and in some distros you'll also find include /etc/nginx/sites-enabled/* this is a convention to keep things organized, you create your server blocks in that conf.d or sites-enabled folder and it would be included here as if it's written in the nginx.conf file.
Of course you can add your own include lines there normally and create your own new conf folder that would be auto included.
TIP: These files are included in alphabetical order, you need to keep that in mind if you don't specify any server as default_server, because first one would be the default.
the general configuration of nginx is in /etc/nginx/nginx.conf. /etc/nginx/conf.d/default.conf is used to configure the default virtual host. For this you can also use sites-available and sites-enabled.
You can find more details at a blog entry from digital ocean How To Configure The Nginx Web Server On a Virtual Private Server
for save time.
if you just have 1 site to host, nginx.conf is ok. but,
if you have 2~n sites, for more clear config, you should use conf.d fold.

Applying NGINX location based on extension of default file.

I'm trying to create an alternate location in NGINX that will only fire for a specific file type. Specifically, I have NGINX acting as a proxy for a server that primarily serves PHP files. There are, however, a bunch of folders that also have ASPX files (more than 120), and I need to use a different configuration when serving them (different caching rules, different Modsecurity configuration, etc).
NGINX is successfully detecting the file type and applying the alternate location when the file name is specifically listed, but it's breaking when the ASPX file is the default file in the folder and the URL simply ends in a slash. When that happens, it's just applying the root location configuration. Is there a way to detect the extension of an index file and apply an alternate location, even when the name of the index file isn't specifically entered?
server {
listen 80;
server_name mysite.com;
# serves php files and everything else
location / {
#general settings applicable to most files
proxy_pass http://#backend;
}
#serves .Net files
location ~* \.(aspx|asmx) {
#slightly different settings applicable to .Net files
proxy_pass http://#backend;
}
}
If a folder has a file called "default.aspx" configured as it's index, the above configuration works perfectly if I enter the url as mysite.com/folder/default.aspx, but it applies only the base location if I enter it as mysite.com/folder, even though it is serving the exact same default.aspx file.
The only solution I've found is to alter the location directive to identify by the folder name instead of the file extension, but this doesn't scale well as there are more than 120 affected folders on the server and I'd end up with a huge conf file.
Is there any way to specify a location by file extension, when the file isn't specifically named in the URL? Can I test a folders index file to determine its extension before a location is applied?

Resources