Nginx Unkown File when restarting after changing default - nginx

I want to set my blog to point towards yourdomainanme/blog and to host a static page on the default yourdomainname.com. I changed the paths but It does not find the html file for some reason.
Error
nginx: [emerg] unknown directive "home" in /etc/nginx/sites-enabled/default:14
nginx: configuration file /etc/nginx/nginx.conf test failed
My Default File
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name yourdomain.com; # Replace with your domain
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 10G;
location / {
root var/www/;
home home.html;
}
location /blog {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}

I believe you are confusing the non-existent home keyword with the index keyword, which tells NGINX the 'default' or 'index' file in the root directory.
location / {
root var/www/;
home home.html;
}
should be
location / {
root var/www/;
index home.html;
}

Related

NginX won't serve static file index.html before go web app

I am using nginx to serve a go web app running on an Ubuntu 18.04 server. I want it to respond to the index directive first when I go to mydomain.com but in the nginx config I have below it is going straight to the web app and ignoring my index.html file. It does work if I get mydomain.com/index.html but won't get that file from index. /var/log/nginx/error.log has no errors.
The static files are chown'ed to root:www-data with chmod 640.
My static files are at /srv/static/ and my go web server is at /srv/web/
Here is my sites-available config file:
server {
listen 80;
server_name mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
server_name mydomain.com;
listen 443 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
root /srv/static;
index index.html;
location / {
try_files $uri #proxy;
}
location #proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8000;
}
}
location / {
try_files $uri $uri/ #proxy; # add $uri/ here
}

nginx config does not get second domain on same server correctly

Setup: Ubuntu 18.04 Nginx Apache Varnish PHP Server
Nginx handles the traffic in the first place.
I have two domains pointing to the same server.
The first Domain works correct, the second one only redirects to the first one.
What is wrong with my configs?
First config which works fine
(Here the nginx works as an reverse proxy for the varnish and Apache.)
upstream varnish {
server 127.0.0.1:6081;
}
upstream apache {
server 127.0.0.1:8080;
}
server {
if ($host = domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80 default_server;
server_name domain1.com;
include inc/acme-challenge.conf;
location / {
return 301 https://domain1.com$request_uri;
}
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2;
#client_max_body_size 120M;
server_name domain1.com;
location /wp-content/uploads {
alias /var/www/website/wp-content/uploads;
include inc/gzip.conf;
include inc/browser-cache.conf;
}
error_page 502 /502.html;
location = /502.html {
alias /var/www/website/502.html;
}
location / {
proxy_pass http://varnish;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
location ^~ /phpmyadmin {
allow 45.77.141.32; #qundg
allow 87.191.170.222; #qundg
deny all;
proxy_pass http://varnish;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem; # managed by Certbot
}
And here ist the second config (this one does not work)
The Domain should only be managed by the nginx without the Apache or Varnish service.
server {
listen 80;
listen [::]:80;
server_name domain2.com *.domain2.com;
root /var/www/domain2.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain2.com *.domain2.com;
root /var/www/domain2.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Here ist the default config
server {
server_name _;
listen *:80 default_server deferred;
error_log /var/log/nginx/default_server_error.log;
return 444;
}
You're using a wildcard in the second DNS name, that should be something that's not recognized in your certificate.
To get a wildcard you could follow instruction here https://medium.com/#saurabh6790/generate-wildcard-ssl-certificate-using-lets-encrypt-certbot-273e432794d7
I have few case in which I have more than 1 DNS pointing to the same website and for those I created different nginx configuration files, and applied for each che certbot authentication. I noticed that using 3rd level dns (something.mysyte.com) in the same config file brouth certbot to override certificates when I had more than 1.
In your specific case you have 2 dns name in the second configuration and one has a wildcard. If you try to remove the dns with the wildcard and reinstall certificates it should work. You can then setup a new block with each 3rd level domain and get certificate for each one, or follow the guide to get the wildcard certificate.

Nginx adding domain

Setting up a site on digitalocean it's working on a default ip that comes with the setup. I've added a domain to the instance and edited the nginx conf file to add a subdomain for testing purposes. I've restarted nginx but the changes aren't taking effect. Here's the conf settings.
upstream app_server {
server unix:/home/django/gunicorn.socket fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _ beta.kazi-connect.com;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://app_server;
}
}

Nginx giving error 403 only on location /

I am trying to serve static html files via nginx. In my nginx config, I have:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/django/django_project/static/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin;
}
location /static {
alias /home/django/django_project/static;
}
location /minion {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
# this is what im talking about
location /html {
alias /home/django/django_project/static/html;
}
location / {
alias /home/django/django_project/static/html;
}
}
(note how the two last definitions are identical aside from the location path). Now, if I go to mywebsite.tld, I get a 403 error for some weird reason, while going to mywebsite.tld/html works exactly as it is supposed to be.
What is the explanation for this behaviour? What mistake did I make so it does this? Obviously, the file perms are ok, the index and files all exist (since /html works), it has to do with the location /, but I dont have a clue why it would... Please help me out here.

Multiple apps on nginx

I'm trying to route traffic across multiple upstream servers on nginx like so:
upstream app_a {
server unix:/tmp/app_a.sock fail_timeout=10;
# For a TCP configuration:
# server localhost:8000 fail_timeout=0;
}
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
index index.html index.htm;
server_name localhost;
root /home/ubuntu/app_a/www/staging/static;
location ~ ^/app_a/(.*)$ {
try_files $1 #proxy_to_app_a;
}
location #proxy_to_app_a {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_a;
}
Unfortunately the apps have no knowledge of full uris and expect to be sitting on root - which means i need to re-write the uri when passing to the app, which is why i thought this might work:
location ~ ^/app_a/(.*)$ {
try_files $1 #proxy_to_app_a;
}
the app works fine if location is just / (because of the aforementioned root issue), but this regex based solution doesnt seem to work. What do i need to do so the app gets / instead of app_a in the url?
Thanks
location /app_a/ {
rewrite /app_a/(.*) /$1 break;
proxy_set_header Host $http_host;
proxy_pass http://app_a;
}

Resources