LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-22-2015, 01:50 AM   #1
linson_85
Member
 
Registered: Oct 2008
Location: Latitude= 9.9722, Longitude= 76.378
Distribution: Open VZ,fedora & Centos
Posts: 47

Rep: Reputation: 0
Trailing slash issue with https redirect - Nginx


Hello,

I'm using following settings for redirecting all http requests to https

Our nginx configuration is as follows

server {
listen 80;
server_name ~^(.*)\.mydomain\.com$;
set $servername $1;
rewrite ^(.*)$ https://$servername.mydomain.com/$1;
error_page 500 502 503 504 /50x.html;
}

SSL conf file

server {

listen 443 ssl;
server_name ~^(?<subdomain>.+)\.mydomain\.com$;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

location / {

root /var/www/html/WebApps1;

}

location /server {
proxy_pass http://mydomain/server;
proxy_set_header Host $subdomain.mydomain.com;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /var/nginx/proxy_temp;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_redirect off;
proxy_cache sd6;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_cache_bypass $http_cache_control;
}

We use wild card DNS. When we use https://webapp.mydomain.com, the static pages loaded from location "/var/www/html/WebApps1" and API requests are forwarded to https://mydomain.com/server


Issue is that when I try to access http://webapp.mydomain.com using current setup, it is redirecting to https://webapp.mydomain.com// ( with two trailing slash at the end of url)

I'm not sure what exactly the problem is. Any suggestion would be of great help.
 
Old 09-23-2015, 12:46 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Issue is that when I try to access http://webapp.mydomain.com using current setup, it is redirecting to https://webapp.mydomain.com// ( with two trailing slash at the end of url)

I'm not sure what exactly the problem is. Any suggestion would be of great help.
Ditch the trailing slash in the rewrite, as it's part of the URI
Code:
rewrite ^(.*)$ https://$servername.mydomain.com$1;
Regards
 
2 members found this post helpful.
Old 09-23-2015, 11:43 PM   #3
linson_85
Member
 
Registered: Oct 2008
Location: Latitude= 9.9722, Longitude= 76.378
Distribution: Open VZ,fedora & Centos
Posts: 47

Original Poster
Rep: Reputation: 0
[Resolved] Trailing slash issue with https redirect - Nginx

Thank you bathory!

That small change worked :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trailing Slash or Not? RobInRockCity Linux - Newbie 5 02-27-2015 10:11 AM
Nginx, Horde, Https, Redirect, This webpage has a redirect loop axetone Ubuntu 0 02-08-2015 10:44 PM
Strange nginx redirects without trailing slash bzzik Linux - Server 11 02-27-2012 08:38 AM
no trailing slash -> apache redirect to microsoft site? SerfurJ Linux - Software 6 03-15-2005 06:25 AM
Apache trailing slash boondock_saint Linux - General 9 07-07-2004 03:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration