Polymer Starter Kit - Pretty URLS on Nginx Server

蓝咒 提交于 2019-12-13 13:28:22

问题


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:


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 <



来源:https://stackoverflow.com/questions/34713474/polymer-starter-kit-pretty-urls-on-nginx-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!