Running If Statement in NGINX website configuration files - nginx

Im trying to use an if statement that allows me to ignore headers only when caching a request. This is the code I implemented ( on /etc/nginx/sites-available/example.com) :
if ($skip_cache = 0) {
fastcgi_ignore_headers X-Accel-Expires Expires Cache-Control;
}
When I run a check on the configuration file's syntax, i get the following error:
nginx: [emerg] "fastcgi_ignore_headers" directive is not allowed here in /etc/nginx/sites-enabled/chartership.com:46
nginx: configuration file /etc/nginx/nginx.conf test failed
Do you guys have any suggestions to steer the implementation correctly?

Related

Kong with OWASP ModSecurity optional configuration include

For customizing of ModSecurity configuration I have included to the modsecurity.conf following line:
Include /etc/modsecurity/*.conf
But without any conf file in the directory (usual case on my enviroment), a kong failing during startup
Error: could not prepare Kong prefix at /usr/local/kong: nginx
configuration is invalid (exit code 1): nginx: [emerg]
"modsecurity_rules_file" directive Rules error. File:
/usr/local/kong/modsecurity.conf. Line: 268. Column: 31.
/etc/modsecurity/.conf: Not able to open file. Looking at:
'/etc/modsecurity/.conf', '/etc/modsecurity/.conf',
'/usr/local/kong//etc/modsecurity/.conf',
'/usr/local/kong//etc/modsecurity/*.conf'. in
/usr/local/kong/nginx-kong.conf:69 nginx: configuration file
/usr/local/kong/nginx.conf test failed
IncludeOptional not supported by kong.
How I can solve the case with optional include?
Kong version 1.2.X

How to setup nginx for a Flask app on a server with Plesk installed

I want to deploy a little Flask webapp on a root cloud server with Plesk installed. I followed this tutorial as it uses Nginx and Gunicorn, like proposed by the developer of Flask: Miguel Grinberg.
The problem is that Plesk has a modified variant of nginx pre-installed named sw-nginx and I've absolutely no clue on how to implement that line of code:
server {
listen 80;
server_name my.subdomain.com;
location / {
include proxy_params;
proxy_pass http://unix:/var/www/vhosts/mydomain.com/my.subdomain.com/myproject/app.sock;
}
}
If I just put in in a .conf file, the configtest of Nginx fails:
$ nginx -t
nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/conf.d/myproject.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
Maybe the syntax of the proxy_pass value is wrong (I tried many, here I put one of them), or maybe the proxy_pass param isn't supported or has to be implemented somewhere else?
PS: I also found this answer How to deploy Flask project on Plesk subdomain
But I read somewhere, that replacing sw-nginx by the standard nginx wouldn't be supported by Plesk. Don't want to break anything...
Thanks for your help.

"ssl_preread" is not working in NGINX

I am trying to implement "ssl_preread" in my nginx. My nginx is compiled with "--with-stream_ssl_preread_module" this module.
I mentioned "ssl_preread on;" in server directive of nginx.conf. But i am getting below error.
nginx: [emerg] "ssl_preread" directive is not allowed here in /opt/nginx/conf/nginx.conf:43
I am following below doc.
http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html
Compile with both modules
--with-stream
--with-stream_ssl_preread_module
Create a stream block outside http block
stream {
upstream app {
server IP1:Port;
server IP2:Port;
}
map $ssl_preread_server_name $upstream {
default app;
}
server {
listen PORT;
ssl_preread on;
proxy_pass $upstream;
}
}
This worked for me. Let me know if this works for you too
Maybe U need to update Nginx to lastest version. 1.10 I meet this error too, but 1.18 the config is OK.
Perhaps this is a late answer. I had the following issue when installing nginx 1.14 from CentOS 8.3 repo.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown "ssl_preread_server_name" variable\nnginx: configuration file /etc/nginx/nginx.conf test failed\n',)
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown "ssl_preread_server_name" variable\nnginx: configuration file /etc/nginx/
nginx.conf test failed\n',)
I fixed it by upgrading the very latest nginx-1:1.20.0-1.el8.ngx.x86_64, following this URL
http://nginx.org/en/linux_packages.html#RHEL-CentOS

Rails 4.2 + NGINX - application root won't load

My server setup works for a Rails 4.0 app, but fails on a 4.2 app. I get this error:
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
NGINX config:
server {
listen 80;
server_name localhost;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
}
NGINX error.log:
2014/10/13 16:17:06 [error] 9261#0: *9 upstream prematurely closed connection while reading response header from upstream, client: ***.***.***.***, server: localhost, request: "GET / H$
Rails production.log:
W, [2014-10-13T16:11:57.305892 #10891] WARN -- : Warning. Error encountered while saving cache a4b17298d22d34199795f642dc5b96ec8d58cc6c/orders.css.scssc: can't dump anonymous class #<$
W, [2014-10-13T16:11:57.314170 #10891] WARN -- : Warning. Error encountered while saving cache a4b17298d22d34199795f642dc5b96ec8d58cc6c/pages.css.scssc: can't dump anonymous class #<C$
W, [2014-10-13T16:11:57.319744 #10891] WARN -- : Warning. Error encountered while saving cache a4b17298d22d34199795f642dc5b96ec8d58cc6c/registrations.css.scssc: can't dump anonymous c$
If I manually put in an index.html file in the public directory, I can see that. But it fails when I want to go to the root path of the app. Any ideas?
OK so this is a bit embarrassing. To further troubleshoot my application, I started in production mode on my local machine, and when I loaded the app I got the following error on the web page:
Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
So that was it. I guess I missed this new security feature by jumping straight from Rails 4.0 to 4.2 Not sure why it didn't show in the logs, but at least I found it eventually.

getting error while using lua with nginx

I am very new to nginx and lua .i have installed Openresty .
below is my code in nginx.conf file .
server{
location /hellolua {
default_type 'text/plain';
content_by_lua ' local name = ngx.var.arg_name or "Anonymous"
ngx.say("Hello, ", name, "!") ';
}
}
When i am running sudo service nginx start i am getting error Starting nginx: nginx: [emerg] unknown directive "content_by_lua" in /etc/nginx/nginx.conf:24
nginx: configuration file /etc/nginx/nginx.conf test failedt
Please let me know what i am missing .
It seems to me, as if you haven't installed the right module? ngx_lua (http://wiki.nginx.org/HttpLuaModule)
You mention OpenResty. Did you configure it with lua? If not, the guide is here(http://wiki.nginx.org/HttpLuaModule#Installation).
Quick resumé:
The ngx_openresty bundle can be used to install Nginx, ngx_lua, either one of the standard Lua 5.1 interpreter or LuaJIT 2.0, as well as a package of powerful companion Nginx modules. The basic installation step is a simple ./configure --with-luajit && make && make install.
You can manually compile ngx_lua into nginx too, the full guide is in the link too.
After comment-discussing - I removed the irrelevant part of the answer.
By default, OpenResty's nginx is installed into the path /usr/local/openresty/nginx/sbin/nginx. Your system's default nginx init configurations need an update to point to the right locations.

Resources