From c9a525bead8b70630a11f8656c7c661976958fb7 Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Sat, 15 Aug 2026 16:43:03 +0330
Subject: [PATCH] fix(nginx): fix invalid if add_header directive and dynamic
backend host
---
nginx.conf | 37 ++++---------------------------------
1 file changed, 4 insertions(+), 33 deletions(-)
diff --git a/nginx.conf b/nginx.conf
index e2368d08..5e0ab60b 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -1,6 +1,6 @@
server {
listen 8080;
- server_name canina.ir stage.canina.ir;
+ server_name canina.ir stage.canina.ir localhost;
# Security Headers
server_tokens off;
@@ -9,24 +9,9 @@ server {
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
- # Block SEO Indexing for Staging Environment
- if ($host = "stage.canina.ir") {
- add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive" always;
- }
-
# Main Application (Next.js)
location / {
- # Basic Authentication for Staging Environment
- if ($host = "stage.canina.ir") {
- set $auth_type "Staging Restricted Area";
- }
- if ($host != "stage.canina.ir") {
- set $auth_type "off";
- }
- auth_basic $auth_type;
- auth_basic_user_file /etc/nginx/.htpasswd;
-
- proxy_pass http://localhost:3000;
+ proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
@@ -36,7 +21,7 @@ server {
# Backend API
location /api {
- proxy_pass http://backend:3000;
+ proxy_pass http://__BACKEND_HOST__:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
@@ -60,28 +45,14 @@ server {
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
- # Block SEO Indexing for Staging Admin
- if ($host = "stageadmin.canina.ir") {
- add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive" always;
- }
-
# SPA routing for Admin Panel
location / {
- if ($host = "stageadmin.canina.ir") {
- set $auth_type "Staging Admin Restricted Area";
- }
- if ($host != "stageadmin.canina.ir") {
- set $auth_type "off";
- }
- auth_basic $auth_type;
- auth_basic_user_file /etc/nginx/.htpasswd;
-
try_files $uri $uri/ /index.html;
}
# Backend API for Admin
location /api {
- proxy_pass http://backend:3000;
+ proxy_pass http://__BACKEND_HOST__:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';