NGIINX Multiple Angular Sites in one server block

18 Views Asked by At

I am trying to serve multiple angular sites in one server block. I cannot get this to work. What am I doing wrong?

My directory structure is like this:

  • /usr/share/nginx/html/apps
    • administration
      • index.html
      • etc...
    • login
      • index.html
      • etc...
    • system-settings
      • index.html
      • etc...
    • ui-showcase
      • index.html
      • etc...

Here is my nginx.conf


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;  

    keepalive_timeout  65;

    gzip on;
    gzip_types application/javascript;
    gzip_buffers 32 8k;

    server {
        listen 0.0.0.0:80;
        listen [::]:80;


        location ~* ^/apps/login {
            include       /etc/nginx/mime.types;
            root /usr/share/nginx/html/apps/login;
            try_files $uri $uri/ index.html /index.html /index.html?$args;
        }

        location ~* ^/apps/system-settings {
            include       /etc/nginx/mime.types;
            root /usr/share/nginx/html/apps/system-settings;
            try_files $uri $uri/ index.html /index.html /index.html?$args;
        }

        location ~* ^/apps/ui-showcase {
            include       /etc/nginx/mime.types;
            root /usr/share/nginx/html/apps/ui-showcase;
            try_files $uri $uri/ index.html /index.html /index.html?$args;
        }

        location ~* ^/apps/administration {
            include       /etc/nginx/mime.types;
            root /usr/share/nginx/html/apps/administration;
            try_files $uri $uri/ index.html /index.html /index.html?$args;
        }
    }
}

I would like to try something like this:

    root /usr/share/nginx/html/apps/;
    location / {
        try_files $uri $uri/ $uri.html =404;

        # location ~* ^/ui-showcase 
        #     try_files $uri $uri/ index.html /index.html /index.html?$args;
        # }
    }

Nothing is working. I am getting either a this site can't be reached, a blank page, a 404, or a 403 page depending on what I tweak to try to make this work.

Any suggestions on what I am doing wrong?

0

There are 0 best solutions below