Score:0

does anyone have a solution for me to access a subfolder of my application behind nginx proxy?

us flag

I have two servers with different IP addresses:

  • Tomcat serving my webapp https://app1.domain.com (centos6)
  • Nginx acting as waf via https://nginx.domain.com (centos7)

Nginx is running on port 443, and I'm using it to reverse proxy my webapp this way:

location /app1/ {
    rewrite ^/app1(.*) /$1 break; 
    proxy_pass https://app1.domain.com/;
}

This way, I normally access my webapp via nginx through https://nginx.domain.com/app1/.

Secondly, in the ROOT folder of my webapp, I installed the birt-viewer application in the ROOT/birt-viewer folder. I normally access the birt-viewer application when I use the link https://app1.domain.com/birt-viewer.

However, I don't normally access the birt application when I use the link https:// nginx.domain.com/app1/birt-viewer. When I copy for example the link

/birt-viewer/Task.jsp?__report=Recare.rpgn&sample=my+parameter&__sessionId=2026

and I paste it after the link https://nginx.domain.com/app1 to obtain the final link

https://nginx.domain.com/app1/birt-viewer/Task.jsp?__report=Recare.rpgn&sample=my+parameter&__sessionId=2026

I access the birt-viewer application but I lose settings such as cookies and sessions.

You understand that to access my webapp via nginx I have to do it manually; the disadvantage is the loss of cookies, sessions and other parameters. Yet access should be done automatically without problems.

This is my nginx config:

user nginxxxx;
worker_processes  1;
error_log /var/log/error.log warn;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
#    include mime.types;
    include /opt/nginx/conf/mime.types;    
    include /opt/nginx/conf/naxsi_core.rules;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/access.log main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    tcp_nodelay on;
    gzip  on;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    client_max_body_size 100m;
    client_body_buffer_size 10K;

    server {
         listen 443 ssl;
        server_name nginx.domain.com;
    access_log on ;
        access_log /var/log/access.log main;
    error_log on ;
        error_log /var/log/error.log warn;
        ssl_certificate /etc/ssl/certs/m.crt;
        ssl_certificate_key /etc/ssl/private/cs.key;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;" always;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
    error_page 403 /403_error.html;
        location = /403_error.html {
            root /usr/share/nginx/htmml;
            internal;
        }

    error_page 404 /404_error.html;
        location = /404_error.html {
            root /usr/share/nginx/html;
            internal;
        }


 location /app1/
         {
rewrite ^/app1(.*) /$1 break;
proxy_connect_timeout 60000;
proxy_send_timeout 60000;
proxy_read_timeout 60000;
send_timeout 60000;
proxy_pass https://app1.domain.com/;
   }

location /app1/birt-viewer/ {
    rewrite ^/app1/folder1(.*) /$1 break; 
    proxy_pass https:// app1.domain.com/birt-viewer/;
}

           }

}

I also realize that once my webapp behind nginx, some urls are not up to date and still keep the old access.

So my concern is to access the birt-viewer application automatically (not manually) through nginx via https://nginx.domain.com/app1/birt-viewer

Does anyone have a solution for me?

user11665472 avatar
us flag
Errata! Errata I meant that I am unable to access files in these folders through **nginx.domain.com/app1/folder1** or **nginx.domain.com/app1/folder2**; I get the 404 error does anyone have a solution for me to access a subfolder of my application behind nginx proxy?
djdomi avatar
za flag
Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers.
user11665472 avatar
us flag
Mister Djdomi Thank you for your comments; I just edited the question with more details.
djdomi avatar
za flag
the showb configuration does not reflect the current used state, are you obfuscated something? please show and share the correct configuration. nginx -T helps you
user11665472 avatar
us flag
Mister Djdomi Once again Thank you for your comments; I just edited the question with the whole nginx config.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.