N
N
NewSantaClaus2021-08-14 16:19:32
linux
NewSantaClaus, 2021-08-14 16:19:32

How to configure nginx location?

Hello dear gurus!

I'm trying to configure the server to work as follows
When accessing my.site, you need to proxy to my.site:5000 (NextJs)
When accessing my.site/api, you need to return responses from the api service (PHP)
When accessing my.site/crm, you need do proxy to my.site:3006(React)

Here is what we have at the moment

location /api {
        rewrite ^(.*)$ /api/public/index.html;
    }

    location /crm {
        proxy_pass http://127.0.0.1:3006;
    }

     location / {
         proxy_pass http://127.0.0.1:5000;
     }


Proxying to port 5000 is good. On 3006 something is not working. When accessing my.site/api, NextJs returns that the page was not found. It turns out that when my.site/api is accessed, it fulfills location /. But this is not necessary. you need to run php in this case

Help me set it up please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2021-08-14
@NewSantaClaus

In the first case, use try_files instead of rewrite
In the second case, /crm will be transferred to the http://127.0.0.1:3006/crm. If you want it to be transmitted as http://127.0.0.1:3006/, then use it http://127.0.0.1:3006/in proxy_pass.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question