M
M
Mr_Smitt2016-07-13 13:17:09
Nginx
Mr_Smitt, 2016-07-13 13:17:09

How to configure Nginx to work with History API in SPA application?

Just started working with Nginx (previously used Apache) and ran into a problem setting up a project configuration.
There are 2 main files in the public folder:

  • index.html - SPA application with History API
  • api.php - Application API.

On Apache, the routing looked like this:
SPA (index.html)
example.com/user
example.com/user/1
example.com/user/1/edit
example.com/user/1/delete
API (api.php)
example .com/api.php/user.list
example.com/api.php/user.view
example.com/api.php/user.edit
example.com/api.php/user.delete
How to make routing work like this in Nginx , so that if there is an /api/ prefix, the data would go to api.php? and the rest in index.html?
I give examples of how it should work:
example.com/param_1/param_2/param_n -> index.html
example.com/ api/ param_1/param_2/param_n.method -> api.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-07-13
@miraage

location /api/ {
  // proxypass php
}

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question