Polymer Starter Kit - Pretty URLS on Nginx Server

2019-06-24 02:33发布

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.

1条回答
爷的心禁止访问
2楼-- · 2019-06-24 02:53

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 <

查看更多
登录 后发表回答