Questions related to nginx location directive should use this tag.
Questions tagged [nginx-location]
1424 questions
5
votes
1 answer
How to set the proxy_protocol to 'on' in a conditional manner in nginx?
Any one familiar with nginx? I am trying to enable proxy_protocol in a conditional manner in a stream block ie for certain endpoints I want the proxy protocol header to be added. For others I dont want to add it. Looking at the documentation there…

Jarvis
- 71
- 3
5
votes
1 answer
Cannot use url to navigate in react through nginx
I am serving my static file using nginx(react frontend).
I have used different urls like /login /user /home for each page.
My nginx doesn't redirect these to my index.html file.
I made some changes and now I cannot get my main page either. It…

Abdul Ahad
- 1,221
- 2
- 16
- 28
5
votes
2 answers
NGINX: Obfuscate password in access_log
I want to log the $request_body in the access logs.
But some of the requests have some JSON fields that are sensitive like passwords.
Example:
[2019-03-28] 201 - POST /api/user/add HTTP/1.1 -…

Raed
- 519
- 1
- 6
- 23
5
votes
4 answers
Why do I get 404 on nginx reverse proxy?
Below is my config and I'm getting 404 on all routes defined apart from the well-known route and I don't understand why.
If I make a request to http://example.tech/connect I get a 404 and if I make a request to http://api.example.tech I also get a…

Jon
- 38,814
- 81
- 233
- 382
5
votes
2 answers
What's the difference between starting nginx with command "nginx", "service start nginx" and "systemctl nginx start"?
I have noticed that when ever I start nginx with ubuntu command "nginx" and I do systemctl status nginx. It shows that systemctl is disabled. More over if I first start nginx with command systemctl start nginx and i try to start nginx with command…

Mahad Ali
- 69
- 1
- 8
5
votes
1 answer
Can I create a "private" location in Nginx?
Can I create a location which can be accessed by any other location in nginx config and cannot be accessed directly from outside?
I can use a deny directive, but it will also deny access to the locations defined in nginx config.
Here's my config -…

Mahesh H Viraktamath
- 818
- 3
- 14
- 34
5
votes
1 answer
configure nginx to make a background request
I am building an application where I need to do some analytics on the api-data combination usage.
Below is my nginx configuration -
location /r/ {
rewrite /r/(.*)$ http://localhost:3000/sample/route1/$1 redirect;
post_action…

John Doe
- 157
- 1
- 10
5
votes
3 answers
serve react frontend and php backend on same domain with nginx
I have a React frontend and a Symfony backend I'm trying to serve on the same domain. The React frontend needs to serve assets if they exist otherwise fallback to serve index.html.
I'd like to serve the php Symfony app when /api is in the request…

David
- 10,418
- 17
- 72
- 122
5
votes
2 answers
How can I redirect non-www to www in https NGINX
I have a question related with Nginx redirects
Bellow you can see configurations.
My goal is to redirect from https://example.com to https://www.example.com
I looked through almost all in stackoverflow and I didn't find any help. Please help me with…

Min MIna
- 51
- 1
- 5
5
votes
2 answers
POST response caching does not work in nginx
My task is to implement microcaching strategy using nginx, that is, cache responses of some POST endpoints for a few seconds.
In http section of the nginx.conf I have the following:
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2…

Roman Puchkovskiy
- 11,415
- 5
- 36
- 72
5
votes
1 answer
proxy_pass based on headers without using if condition
I'm looking for a way to reroute all requests that have set an account-id in the HTTP header Account-ID with the last two digits (of a ten digit number) 00 to 05 (to touch only 5% of the total traffic). In addition, if a request has set the HTTP…

user3105453
- 1,881
- 5
- 32
- 55
5
votes
2 answers
Regex to find files matching file extension except if filename contains string
I have caching enabled for specific files in nginx, like this:
location ~* \.(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
What I'd like to do here is to exclude…

mavericko
- 63
- 1
- 5
5
votes
1 answer
Nginx return under location
I am currently facing a small problem using nginx to redirect to another host. I want to for example redirect https://service.company.com/new/test.html to https://new-service.company.com/test.html .
For now I have following configuration, which…

jcrosel
- 349
- 2
- 5
- 13
5
votes
0 answers
Adding a prefix to the location in nginx
I want to add a location with a prefix so that my app works similar to the one without slash,
eg:
server_name mydomain.com
location /{
proxy_pass http://127.0.0.1:8000;
}
with the above config, the app is working, but I have multiple apps to be…

IAmHomes
- 513
- 2
- 11
- 20
5
votes
1 answer
Nginx - another root for a specific location
I have some static html files under:
/var/www/project1
Nginx config for this project is:
server_name www.project1.com project1.com;
root /var/www/project1;
location / {
index index.html;
}
My goal is…

Milos Cuculovic
- 19,631
- 51
- 159
- 265