Nginx dynamic load balancing - nginx

How do I have to create my /etc/nginx/nginx.conf for using the REST-API? The Loadbalancing works fine, though. But creating an API endpoint does not function as I thought it should be.
When I try to start the service, it fails with this error message:
nginx: [emerg] unknown directive "api" in /etc/nginx/nginx.conf:27

Related

How to log "x-kong-proxy-latency" in custom log formatter in Kong

I would like to log values of "x-kong-proxy-latency" and "x-kong-upstream-latency" headers to Kong log. How can I get access to those value in log_format?
KONG_PROXY_ACCESS_LOG: /dev/stdout custom_formatter
KONG_NGINX_HTTP_LOG_FORMAT: custom_formatter 'xkpl $$x_kong_proxy_latency'
This gets me an error:
2022-11-20 00:13:18 Run with --v (verbose) or --vv (debug) for more details
2022-11-20 00:14:20 Error: could not prepare Kong prefix at /usr/local/kong: nginx configuration is invalid (exit code 1):
2022-11-20 00:14:20 nginx: [emerg] unknown "x_kong_proxy_latency" variable
2022-11-20 00:14:20 nginx: configuration file /usr/local/kong/nginx.conf test failed
Now, what is the correct way to get this data in a variable?
As the error implied, x_kong_proxy_latency is not a variable nginx knows by default.
x-kong-proxy-latency and x-kong-upstream-latency are HTTP headers that are sent to the client indicating kong latency and upstream latency respectively
Since these headers are created by Kong to send t clients, we can use $sent_http_ nginx's prefix to inject the header into access_log, for example:
KONG_PROXY_ACCESS_LOG:/dev/stdout latency
KONG_NGINX_HTTP_LOG_FORMAT:latency '$$sent_http_x_kong_proxy_latency $$sent_http_x_kong_upstream_latency'
will inject the value of both headers you're looking for.
In case you are looking for more configs, you can look at the nginx document here

Running If Statement in NGINX website configuration files

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?

Nginx gives a FormatMessage() error out-of-the-box on windows 10

I'm having trouble setting up nginx 1.13.5 on windows 10.
I downloaded the windows binary from the nginx site.
I ran the executable using the example config file and got the following error:
nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: FormatMessage() error:(15100))
Google turned up empty.
No matter what I do the error doesn't go away and I cannot find any information about it.
I checked if anything was running on port 80 but nothing is.
I had a windows process (WAS) using port 80. Shutting it down fixed it.

nginx not running that displays 404 message

I've been following the directions based on http://linoxide.com/linux-how-to/install-configure-femp-stack/
So far when I ran my ip address http://ip address
I got an error that says "404 not found."
I've already enable sysrc nginx_enable=yes and that one works
Next I tried nginx -t and that part works and it says:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Then I tried nginx result and it it didn't work and I got the message saying "invalid option: "result"" it didn't work then I tried service nginx start and
it start running and when I type my ip address I kept getting 404 message.

New MediaTemple site displays '404 File Not Found - nginx' message

I just set up a new new domain and uploaded some simple static html files & assets. The images do not display and when I try to pull one up directly in the browser I get a page that reads
404 File Not Found - nginx
This is weird because although I know media temple uses nginx to run the VMs, the websites are always served up with apache...
Anyway, what led up to this was that I:
created a new webspace
created a new domain within that webspace
uploaded a new image (logo.jpg)
found that logo.jpg would not load and leads to the 404 described above
After creating the new domain, I got an automated message shown below (with specific info removed):
---------- Forwarded message ----------
From: [user] [email]
Date: Thu, Jan 30, 2014 at 12:40 PM
Subject: Unable to configure a web server on the host [domain]
To: [me]
Unable to generate the web server configuration file on the host [domain] because of the following errors:
nginx: [emerg] listen() to [ip address]:80, backlog 511 failed (98: Address already in use)
nginx: configuration file /etc/nginx/nginx.conf test failed
Please resolve the errors in web server configuration templates and generate the file again.
What is the issue here? It's a brand new site - it shouldn't be giving me this kind of grief..
Ok, I have no idea what upset nginx, but the nginx configuration file needed to be refreshed. This was accomplished with the following ssh commands:
/usr/local/psa/admin/sbin/nginxmng --disable
/usr/local/psa/admin/sbin/nginxmng --enable

Resources