Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer Starter Kit - Pretty URLS on Nginx Server

the Polymer Starter Kit (PSK) contains instructions on using Pretty URLs when hosting on Firebase HERE

I am attempting to do similar using Nginx Server, but cannot figure out the Location Block for page reloads. Using the sample data that comes with PSK, how would you configure "/users/sam", for example.

like image 212
Where Solutions Avatar asked Dec 25 '22 10:12

Where Solutions


1 Answers

nginx config

server {
  listen 80;
  server_name example.com;
  root /home/myuser/psk/dist;
  index index.html;

  location /
  {
    try_files $uri /index.html;
  }
}

Make sure to add a base url to your index.html. In case of Polymer starter kit & nginx the base element will help direct access to URLs with query parameters such as : http://example.com/users/Chuck that you can find under "Users" in PSK 1.2.x

<html>
  <head>
    <base href="/">
    ...

Otherwise nginx will go into a loop without a base URL.

nginx error.log

rewrite or internal redirection cycle while internally redirecting to "/index.html"

Browser goes into an infinite cycle loading the index page instead of static files.

Uncaught SyntaxError: Unexpected token <

like image 142
Tanbouz Avatar answered Jan 04 '23 21:01

Tanbouz