Nginx remembering old subdomain - nginx

I am having a weird issue. My ubuntu server is still remembering an old subdomain, even though the configuration files is deleted, both symlink and the original one.
The nginx service is restarted, and the health is just fine as seen below:
website:/etc/nginx/sites-enabled# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Why on earth is the old subdomain still accessible? there is no specific DNS settings for the subdomain, all I have is
*.domain.com | ip
www.domain.com | ip
This is the contents of nginx:
website:/etc/nginx/sites-enabled# ls
- is empty
website:/etc/nginx/sites-available# ls
- is empty
Nginx conf:
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;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
I have tried to disable nginx caching, but still it's like its remembering the old subdomain somehow. Any experience on this?

Related

NGINX redirecting to default server page

I'm trying to deploy an app to an Ubuntu 20.04 server with NGINX. My static build files are under /var/www/html directory. The issue I'm getting is that, when accessing the website through the domain name, the default server page (blank, with one line of text detailing server info) shows instead of my static files.
I tried changing the server_name and root values in the config file under "sites-available" directory. No matter whether I use the domain name or the IP address, I still get the same result.
This is the config file under sites-available:
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
And this is the default nginx.conf file:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
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;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
your question is off-topic here and should be asked on serverfault.
There are a number of things missing from your description which I would expect to see. While this does not point to a definitive cause for your issue, they may be contributory factors:
Regarding....
This is the config file under sites-available:
On Ubuntu, Nginx ignores this directory - it looks in /etc/nginx/sites-enabled for the specific sites to run. The files themselves should reside in /etc/nginx/sites-available and be symlinked from /etc/nginx/sites-enabled
If you want multiple sites on your server then you should have at least 2 files visible in /etc/nginx/sites-enabled, a default one like this....
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html;
...
(Note the "default_server" and "server_name _") and one for each named server.
IME, Nginx needs to load the default config first. And it loads the files in alphabetical order. So a symlink named "a.example.com" will be loaded before "default". On my servers, the default config is named "_default"

NGINX - Why i am getting "Permission denied" error code 13?

i finished setup of my first nginx server and i noticed the following error on nginx t command.
Error mesage:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2020/12/12 19:25:26 [warn] 1498#1498: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/12/12 19:25:26 [emerg] 1498#1498: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
My NGINX config file as is now:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
# For Basic Auth
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
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;
# SSL Settings
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Gzip Settings
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 1100;
# Virtual Host Configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# Harden nginx against DDOS
client_header_timeout 10;
client_body_timeout 10;
keepalive_timeout 10 10;
send_timeout 10;
}
How can i fix this error? Is my config file fine? I am using a raspberry pi as a home server for my projects. I am using SSH to communicate with my server and i am able to read with sudo nano the error log file.
MUST use sudo and not simple nginx t...
The correct command:
sudo nginx -t
And the output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Ubuntu 18.04 Nginx - always only shows the welcome page

I am using Ubuntu 18.04 default nginx configuration, with some minor changes. But I always sees the nginx's default welcome message. All config files follows:
/etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
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;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/conf.d/default.conf:
This file is empty. And this directory only contains one file.
/etc/nginx/sites-enabled/default:
upstream backend {
server 127.0.0.1:8068;
}
server {
listen 80;
listen [::]:80;
# server_name _;
location / {
proxy_pass http://backend;
}
}
On the server, the http server runs correctly:
$ curl 127.0.0.1:8068
some contents...
In another computer, only the welcome message shows:
$ curl http://the-server-ip-address
the default welcome to nginx message follows...
I've also tried to access the ip address in my Chrome and disabled caches, but the same welcome page always shows.
/var/log/nginx/access.log and /var/log/nginx/error.log shows no access logs and no errors.
Does my nginx config files have a problem? Thanks!
(I just tried the same config files on a 16.04 ubuntu server and it works correctly.)
I've run the follow commands to test and reload the configs:
$ nginx -t
$ nginx -s reload
updated
Sorry, I just tried some other operation:
I run the following command on this server:
$ ifconfig
and get the ip address is 192.*** rather than the ip address I used to access(ssh to) this server.
I run
$ curl 192.***:80
and the server responds correctly.
But why the ip address I used to ssh to the server always shows the welcome page?
$ curl the-server-ip-address-for-ssh:80
still the welcome page...
Thanks!

NGINX not serving CSS, Images and other media files

I have installed NGINX on my ubuntu 16.04 LTS server to satisfy the need to navigate to different applications on the same linux server.
So I have installed it and followed this tutorial : https://www.youtube.com/watch?v=PTmFbYG0hK4&t=677s
I defined it exactly as the tutorial shows but I ran into a problem where the NGINX not serving any media files for a specific application (CSS, Images, stylesheets etc). I will be clearer: I defined inside sites-available a configuration file as such (of course I made a symbolic link to the sites-enabled directory.):
server{
listen 80;
listen 443 ssl;
location / {
root /home/agent/lexicala;
}
location /test {
proxy_pass "http://127.0.0.1:5000";
rewrite ^/test(.*) $1 break;
}}
The "location /" - serving my HTML files and website perfectly.
But when I try to approach to "MyServersIP/test/" (serving a node app) which supposed to be served from "location /test" - the routing is good but NGINX serving it without any media.
On the chrome console I have inspected it in chrome and see the following errors:
GET http://MyServersIP/stylesheets/style.css net::ERR_ABORTED
GET http://MyServersIP/scripts/jquery.multiselect.js net::ERR_ABORTED
GET http://MyServersIP/css/jquery.multiselect.css net::ERR_ABORTED
I have tried to follow posts which I saw that people ran into the same problem:
Nginx fails to load css files ;
https://superuser.com/questions/923237/nginx-cannot-serve-css-files-because-of-mime-type-error ; https://www.digitalocean.com/community/questions/css-files-not-interpreted-by-the-client-s-browser-i-think-my-nginx-config-is-not-good
And many more, but nothing worked for me.
Another thing worth mentioning - when I swap routings like this:
server{
listen 80;
listen 443 ssl;
location / {
proxy_pass "http://127.0.0.1:5000";
}
location /test {
root /home/agent/lexicala;
rewrite ^/test(.*) $1 break;
}}
The node app is served perfectly, but it is not good for me as I want the users to approach my node app through the 'test' URL.
This is my nginx.conf file (I have made no changes):
user www-data;
worker_processes auto;
pid /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;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
I tried to supply as much details as I could but if something is missing I would be glad to add.
Hope you guys help me find solution to this bug cause I spend over it good working days.

Nginx not serving www.example.com but serves example.com

I am having problem getting www.example.com to work. Website loads on example.com but not on www.example.com. My current config file /etc/nginx/sites-available/example.com is
server {
listen 80;
server_name www.example.com;
return 301 http://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
root /path/to/dir;
index index_en.html index.html;
}
I have tried different approaches with config, none worked. I also removed the example.com block and went with only one for www.example.com, yet www.example.com didn't work, but example.com still did. Of course I restarted nginx after every change.
I have DNS records for both, example.com and www.example.com, both A and pointing to same IP. I have also tried CNAME-ing one to another, waited for few hours and nothing. Still the same. Now I am getting really pissed off, because with other subdomains everything is working perfectly, just not with www.
And yeah, if I search for www.example.com on Firefox on Ubuntu 14.04, I get Server not found.
# /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /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";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# 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/*;
}
I left mail section out because it is completely commented out.
It probably had to do with some local DNS settings on LAN and local DNS cache, because I was able to access the site from other networks.

Resources