How do I set a default base path and redirect path for nginx location?

Viewed 34

I am still getting my feet wet with learning about nginx configurations. I am currently able to use the following blocks to proxy some UI files from S3 through an ALB in AWS. I am having issues, though, setting the location paths.

I am only able to access the angular application at the following: https://domainname/index.html

What I am needing is to access the UI files at https://domainname/appname and then load all the files from there. How do I do this? Here is my current nginx.conf file.

server {
        listen 80;
        server_name <servername>.com;
        resolver 8.8.8.8 valid=30s;
        index index.html;
        gzip_types text/plain application/xml application/x-javascript text/css application/json text/javascript;

        location ~* ^/(.*) {
            set $S3BUCKET "<bucketnamepassedinhere>.s3.amazonaws.com";
            proxy_buffering        off;
            proxy_ignore_headers   "Set-Cookie";
            proxy_hide_header      x-amz-id-2;
            proxy_hide_header      x-amz-request-id;
            proxy_hide_header      x-amz-meta-s3cmd-attrs;
            proxy_hide_header      Set-Cookie;
            proxy_set_header       Host $S3BUCKET;
            proxy_set_header       Connection "";
            proxy_intercept_errors on;
            proxy_pass https://$S3BUCKET/$1;
            break;
        }
    }
1 Answers

Check for this one :

server {
 listen 80;

 location / {
  proxy_buffering        off;
  proxy_set_header       Connection "";
  proxy_set_header       Authorization '';
  proxy_set_header       Host humtydumty.dev.s3.amazonaws.com;
  proxy_hide_header      x-amz-id-2;
  proxy_hide_header      x-amz-request-id;
  proxy_hide_header      x-amz-meta-server-side-encryption;
  proxy_hide_header      x-amz-server-side-encryption;
  proxy_hide_header      Set-Cookie;
  proxy_ignore_headers   Set-Cookie;
  proxy_intercept_errors on;
  add_header             Cache-Control max-age=31536000;
  proxy_pass             http://humtydumty.dev.s3.amazonaws.com;
}

Hope this answer helps you!

Related