fix(nginx): fix invalid if add_header directive and dynamic backend host
Deploy Canina / deploy (push) Successful in 2m45s
Deploy Canina / deploy (push) Successful in 2m45s
This commit is contained in:
1 parent
0fb83142d6
commit
c9a525bead
1 file changed
+4
-33
+4
-33
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user