PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

[FIXED] how to set the locaction in nginx.conf for removing URL's trailing slash?

 September 02, 2022     nginx, nginx-location, nginx-reverse-proxy, vue.js     No comments   

Issue

Today I used two servers for nginx, the content of nginx.conf as follows:

#192.168.2.98
server {
    listen 8091;
    location ^~ /ttank {
        alias /develop/servers-running/front/vue-public/dist;
        index index.html;
        try_files $uri $uri/ /ttank/index.html;
     }
 }



#192.168.2.97
location /ttank {
   proxy_pass http://192.168.2.98:8091;
   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_redirect off;
}

I can access the 192.168.2.98:8091/ttank by enter address: http://192.168.2.98:8091/ttank in chrome, I also can access 192.168.2.98's ttank by entering the address http://192.168.2.97/ttank/, but when I change the addres http://192.168.2.97/ttank/ into http://192.168.2.97/ttank, my chrome entered into waiting status forever, the only difference between two addresses is the last "/", I don't know how to modify the config file for removing the last "/" when accessing ttank by 192.168.2.97?


Solution

Try usinge a rewrite rule to get rid of the ending slashes

location /ttank {
    rewrite ^/(.*)/$ /$1 break;
    ...;
    ...;
    proxy_pass ...;
}

it should do it



Answered By - OldFart
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing