How to enable nginx status page? - nginx

I need the IP/nginx_status page for my check_nginx_status Nagios plugin. I followed some instructions:
nginx -V | grep --color -o http_stub_status #some HttpStubStatusModule verification
In nginx.conf, I added:
http {
...
server{
location /nginx_status {
stub_status on;
access_log off;
allow MY_IP;
deny all;
}
}
...
}
After nginx reload, the page should be available.
But, I get "The page you were looking for doesn't exist."
I have nginx v1.6.0.
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
server {
listen 80;
location /nginx_status {
stub_status on;
access_log off;
#allow 107.170.106.199;
#deny all;
}
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

Related

nginx doesn't serve "/" path

I have a domain example.com which is registered and working.
I am now trying redirect all requests to example.com and www.example.com to a specific port.
the default config in sites-enabled looks like this:
server{
listen 80;
listen [::]:80;
server_name example.com www.example.com;
location / {
return 301 https://example.com:8081/;
}
}
the above config does not work (when accessing example.com in the browser, i get infinite loading)
While when using this config, example.com/test works.
server{
listen 80;
listen [::]:80;
server_name example.com www.example.com;
location /test {
return 301 https://example.com:8081/;
}
}
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/sites-enabled/*;
}

nginx backup directive in upstream not working

this is my Nginx config file that is embedded in k8s configMap.
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
upstream backend {
server flask1-service.mohammad-elastic.svc.cluster.local:8080 weight=5;
server flask2-service.mohammad-elastic.svc.cluster.local:8081 backup;
}
upstream test_backend {
server flask2-service.mohammad-elastic.svc.cluster.local:8081;
}
server {
server_name mirroring;
listen 80;
access_log /var/log/nginx/proxy.log;
error_log /var/log/nginx/proxy.error.log info;
location / {
mirror /mirror;
proxy_pass http://backend;
proxy_next_upstream http_404 non_idempotent;
}
location = /mirror {
proxy_pass http://test_backend$request_uri;
}
}
}
when the flask1 ,primary app, is down, flask2 app, as backup, doesn't work.
I mean sometimes the request get result but most of the time it gets 502 bad gateway.

How to remove header server nginx

Using ubuntu server 20.04, nginx version: nginx/1.17.10 (Ubuntu), localhost,
when I shut down my dot net application, "502 Bad Gateway" following by nginx appears ( version is hidden successfully). I did this to hide nginx:
sudo apt-get update -y
sudo apt-get install -y nginx-extras
sudo nano /etc/nginx/nginx.conf
http {
more_set_headers "Server: Your_New_Server_Name";
server_tokens off; }
sudo service nginx restart
Refrence
Even tried
more_clear_headers Server;
more_set_input_headers -r 'Server: howdy';
but still having problem. All the web suggest just the same way, but not working to me.
My currently nginx.conf :
user ehsan1362;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_tokens off;
# more_clear_headers Server;
#more_set_input_headers -r 'Server: howdy';
add_header X-Frame-Options "SAMEORIGIN";
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/proxy.conf;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

NGINX 502 Bad Gateway with node app

I'm having a problem with my website.The site is down error "502 Bad Gateway" from nginx. I restarted the server and there are no errors. The site ran for months and now there is this error.
The node app is still running. Nothing changes there. The website is hosted on digitalocean and everything seems fine.
Site is located home/naoufal/mlg not inside www
app.js
var port = process.env.PORT || 8888;
sites-available/default
server {
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
nginx.config
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
What's wrong?
Thanks.
Edit: The site is now working for no particular reason. I think it was a problem with Digital Ocean not on the code itself.

nginx won't start after lets encrypt update

After updating y let's encrypt domain update, I can't start Nginx. I got a message :
nginx: [emerg] zero size shared memory zone "one".
I did not find any solution, did anyone solve it ?
I saw that this memory is used by my 4 workers, I added a proxy but my server still does not restart.
Thank you
user nginx;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1.2;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#proxy
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=app_cache:10m max_size=5g inactive=45m use_temp_path=off;
}
Eventually I found this line in one of my config files and commented it :
# limit_req zone=one burst=1 nodelay;
Thank you Shawn
Jean

Resources