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"
Related
I'm trying to create a basic api which does stuff, as an api does, however it is sitting behind both an Nginx instance and a Cloudflare layer for security, however every time I make a request all the headers go through find but the body of the request (application/json) seems to be getting removed.
I have tried logging it on the nginx instance and I just get '-' every request so I think it could be Cloudflare. I have tested locally and I am definitely able to receive the body as it is. I've looked through the req object and there is no body anywhere, all the auth headers are fine just the body.
EDIT (in response to AD7six): Sorry i'll clear my question up, i'm saying that both the access log is missing the body and that my code behind the proxy does not receive it. I'll attach the nginx config / log now.
On further inspection my nginx config is listening to port 80 however all the responses are going to https... I hope that makes sense.
NGINX Config
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
log_format postdata $request_body;
##
# 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/*;
server {
listen 80;
listen [::]:80;
server_name dev.ru-pirie.com;
location / {
access_log /var/log/nginx/postdata.log postdata;
proxy_pass http://192.168.1.74:3000;
}
}
}
All the log contains is - per request
When requests are proxied via Cloudflare, by default they are modified with additional headers, for example CF-Connecting-IP that shows the IP of the original client that has sent the request (full list here).
There are other features that Cloudflare users can implement that may alter the request, but only when explicitly configured to do so: for example, someone could write a Cloudflare Worker that modifies arbitrarily the incoming request before forwarding it to the origin server. Other general HTTP request changes are possible using Cloudflare Rules.
Cloudflare would not alter the body of an incoming request before passing it to the origin, unless explicitly configured to do so for example with Workers.
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!
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.
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.
i setup a virtualbox with a clean install of ubuntu 16. installed nginx, php7, mysql all fine. the computer name is: mercury
i've setup a folder that would be the root for all my web projects: /var/www
i want to be able to have a dynamic virtual host where i can just create a folder (like: /var/www/project1) and i'll easily be able to access it via the browser at: project1.mercury
i can i achieve this? in my browser: mercury/ loads up fine (/var/www/index.html), but as soon as I use a subdomain it craps out and gives me a dns error: server DNS address could not be found
here is my: /etc/nginx/nginx.conf file
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
worker_rlimit_nofile 30000;
events { worker_connections 1024; }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/xml text/css text/comma-separated-values;
upstream app_server {
server 127.0.0.1:8080 fail_timeout=0;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/default:
server {
listen 80;
server_name ~^(?P<subdomain>.+)\.mercury$;
location / {
root /var/www/$subdomain;
}
}
UPDATE:
so this config works, but i need to manually update my Windows hosts file and specify the subdomain with the same ip address:
192.168.1.101 project1.mercury
if i dont, i get a dns error.
how can this be achieved without having to manually add an entry in the hosts file everytime??