http.Redirect is not working with nginx config

Viewed 149

My http.Redirect is as below:

http.Redirect(iWri, pRq, "/report/"+UD.TID+"/_report/last_report.html", http.StatusFound)

Here UD.TID = 2022066A4KIFTXUUP2WQO7, or something like that, but my Router code is like below:

oRouter.PathPrefix(
    "/report/{id:[0-9]{6}[A-Za-z2-7=]{16}}/{path:.*}",
).Methods("GET").Handler(
    mwBaseCompressed.ThenFunc(apiParam.ReportServerHandler()),
)

My folder structure where the last_report.html is stored is as below:

"/Users/myname/projbuild/prod/project_v2/_var/QCACHE/2022/06/6A4KIFTXUUP2WQO7/_report/last_report.html"

The above combination is working fine when we run frontend (vue) and backend (go) on local or dev server, means the string 2022066A4KIFTXUUP2WQO7 somehow get split into 2022/06/6A4KIFTXUUP2WQO7 and report get displayed.

BUT on the production server we are using Nginx server and nginx conf is s below for /report,

location /report/ { alias /home/admin/_var/QCACHE/; }

with Nginx the string 2022066A4KIFTXUUP2WQO7 doesn't get split and remains same so application can't show report. Same is working fine with haproxy.

1 Answers

Added below block in my nginx.config, basically i found out all the routing calls from my main.go (oRouter.Handle) and then used them as below to configure in nginx,

location ~ ^/(api|ufile|report|uad|pimg|xml|constants.js|test){
                               proxy_pass http://127.0.0.1:9999;
                               proxy_set_header X-Forwarded-Host $host;
                               proxy_set_header X-Real-IP $remote_addr;
                               add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
                             }
Related