How to conf nginx worker_connections with cf buildpack staticfile - nginx

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.

Related

Nginx: How to set environment variable in server block

Simply, I want to achieve same thing of apache vhosts: Set Application_ENV via virtual host config and read this in PHP for nginx. How to do that?
One way to do it is use fastcgi_param as answered here and here.
I prefered another method. Since I'm using GIT as my VCS:
I created a file in the root of my project named it "env.conf",
which contains only 1 string ("production", "development", etc) which is the environment name
Ignored this file in .gitignore.
Read the file and check the value as the first thing in my application starting point.

Access_log coming with date and time

I need to use access_log for some automation purpose.
After sometime access_logs are coming with date and time, i want to keep it with the name access_log only.
I have given the name in squid.conf but that is not working for me.
please suggest.
First, check your Squid configuration file and make sure there is no logfile_rotate parameter specified.
Then, check your operating system's logrotate.d folder for a configuration file directing it to rotate Squid's configuration file, and either remove the file completely, or rename it so it has a ".disabled" extension (may not work on all distributions).
On CentOS the logrotate configuration can be found at /etc/logrotate.d/squid.

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

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;
}

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