0

i have hosted a webapp in nginx that need to make a http request to the api server hosted in same nginx server , the req.body data is working sucessfully between the two servers, but the authorization header is not received by the webapp hosted in the nginx, but the header can receive by the api server when running the webapp local.

This is my api server block

   server {


        #root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name bio.api.mindvisiontechnologies.com;

        location / {
        proxy_pass http://localhost:7777; #whatever port your app runs on
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header Authorization $http_authorization;
        proxy_cache_bypass $http_upgrade;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/bio.api.mindvisiontechnologies.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bio.api.mindvisiontechnologies.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

THIS IS THE WEBAPPP SERVER BLOCK

server {
        root /var/www/html/bio.mindvisiontechnologies.com;
        index index.html index.htm;
        server_name bio.mindvisiontechnologies.com;


   location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization $http_authorization;

        try_files $uri $uri/ /index.html;
   }




    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/bio.mindvisiontechnologies.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bio.mindvisiontechnologies.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = bio.mindvisiontechnologies.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name bio.mindvisiontechnologies.com;
    listen 80;
    return 404; # managed by Certbot


}

THIS IS MY NGINX CONFIG

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##
        underscores_in_headers on;
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        log_format custom '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent" '
                          '"$http_authorization"'
                          '$request_body';





        access_log /var/log/nginx/access.log custom;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

can anyone help me to solve this issue

Venkat Cpr
  • 153
  • 1
  • 11
  • This can be useful. https://serverfault.com/questions/785251/nginx-location-block-add-header-not-working-when-try-files-exists – Xirehat Apr 08 '23 at 06:02

0 Answers0