I'm creating an Angular 9
application with a Loopback 4
backend using nginx
.
When using ng serve
I can navigate to different pages and refresh the page without issue. However after pushing to the staging server, I can navigate the app but if I refresh any page that isn't staging.mydomain.com/
I get a 404 error.
I've tried adding try_files $uri $uri/ /index.html;
to the location
section of my nginx.conf
file, but when I do that the even the index page doesn't load any more.
Below you'll see the the server
section of my nginx.conf
file:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name staging.mydomain.com; # managed by Certbot
root /usr/share/nginx/html;
ssl_certificate /etc/letsencrypt/live/staging.mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/staging.mydomain.com/privkey.pem; # managed by Certbot
# Load configuration files for the default server block.
include /etc/letsencrypt/options-ssl-nginx.conf;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
#try_files $uri $uri/ /index.html;
proxy_pass http://127.0.0.1:3004;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Conneciton 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name staging.mydomain.com;
return 301 https://staging.mydomain.com$request_uri;
}
Is anybody able to provide some guidance to get my deep links working correctly?