A
A
Anatoly Chernyshev2019-06-18 15:36:31
Nginx
Anatoly Chernyshev, 2019-06-18 15:36:31

How to configure virtual hosts for NGINX for ajax?

There is such a task. Place two virtual hosts on one domain name.
First host. Gives and works with statics written in VueJS
Second host. Receives Ajax requests from VueJS and passes them through passenger to the rails application
Please tell me. How can I configure the host for rails so that it only accepts ajax requests, and normal requests from the browser go to static

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neatsoft, 2019-06-18
@kayn23

There are three options for solving this problem:
ps. I advise you to pack your services in Docker containers, and use Traefik instead of Nginx as a reverse proxy / tls proxy / load balancer. Its killer features are auto discovery and auto load balancing. In addition, it is much easier to properly configure it. Traefik itself also runs in a container, so nothing is required on the server other than docker and docker-compose
traefik-architecture.svg

V
Vladimir Skibin, 2019-06-18
@megafax

You need to arrange everything in such a way that all the statics are in the "doc_root" folder of your application and you process them directly with nginx in regular intervals. And send all requests via ajax along the path / api / and redirect it to your back. Everything else is resolved at the Vue level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question