Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPS Redirect not working on Nginx #6

Open
jonyoi opened this issue Apr 11, 2018 · 20 comments
Open

HTTPS Redirect not working on Nginx #6

jonyoi opened this issue Apr 11, 2018 · 20 comments

Comments

@jonyoi
Copy link

jonyoi commented Apr 11, 2018

I am using LEMP stack with Virtualmin which I installed using "--bundle LEMP" while installing virtualmin on a debian9 OS.

When I below settings, The https redirect is not working on any of the domains.

System Settings --> Virtualmin Configurations --> SSL Settings --> Redirect all http to https by default --> yes

However I am able to do the redirect by adding below code in domain.com.conf

server {
server_name domain.com www.domain.com;
listen ipaddress:80;
rewrite ^/(.*) https://domain.com/$1 permanent;
}

But I wonder why the inbuilt feature that ships with virtualmin is not working?

Please note I am using Lets' Encrypt SSL.

on other note I wonder what type of Redirect Virtualmin does if that feature is to work? Is it also 301 redirect?

Any help on this would be immensely helpful.

Thanks

UPDATE: I created this thread back in 2018 where I used virtualmin briefly when I was testing it out. I never really used virtualmin to it's extent.

I can't believe this is still an issue after 5 years. I have been receiving notifications about it, so I came here to update this thread and unsubscribe from it, as I can't really figure out how to delete this thread.

@jcameron
Copy link
Collaborator

Doesn't this only work if you have a separate server block for SSL and non-SSL though? Otherwise there would be an infinite redirect.

Unfortunately Virtualmin currently only uses a single server block for both protocols (unlike Apache).

@pixel-paul
Copy link

I have recently run into a similiar issue, where we needed to redirect www. to non-www.

Nginx expects something similar to this to deal with this scenario:

server {
    	server_name www.example.com;
	listen 443 ssl http2;
	ssl_certificate /etc/ssl/virtualmin/16848264071884359/ssl.cert;
	ssl_certificate_key /etc/ssl/virtualmin/16848264071884359/ssl.key;
    	return 301 $scheme://example.com$request_uri;
    }

server {
		server_name example.com;
		listen 443;
                ssl_certificate /etc/ssl/virtualmin/16848264071884359/ssl.cert;
	        ssl_certificate_key /etc/ssl/virtualmin/16848264071884359/ssl.key;
                ......
      }

@jcameron
Copy link
Collaborator

The latest version of Virtualmin does support different redirects for HTTP and HTTPS, which you can create in the UI.

@pixel-paul
Copy link

pixel-paul commented Jul 19, 2023

I did try and use the UI to create this www.example.com --> example.com redirect, but I couldn't figure it out:

image

The above errors with:

Failed to save redirect : Missing or invalid source URL path

Which makes sense of course, as this form is for a redirect based upon the source path relative to the virtual server domain.

@jcameron
Copy link
Collaborator

The source URL path should be just /

@pixel-paul
Copy link

I have tried this and I still get the Failed to save redirect : Missing or invalid source URL path error

image

@jcameron
Copy link
Collaborator

Are you sure there's not a space at the start or end of the path?

@pixel-paul
Copy link

Yes:

Screen Shot 2023-07-21 at 09 31 16

@jcameron
Copy link
Collaborator

Hmm, this is very confusing. Can you check which version of Virtualmin and the Nginx plugin you're running there?

@pixel-paul
Copy link

pixel-paul commented Jul 24, 2023

SYSTEM INFORMATION
OS type and version Rocky Linux 9.2
Webmin version 2.021
Usermin version 1.861
Virtualmin version 7.7  
Theme version 20.21
Package updates All installed packages are up to date
Webmin module Nginx Webserver 2.30-1
Webmin module Nginx Webserver SSL 1.19-1

@jcameron
Copy link
Collaborator

We just released Webmin 2.100 - try upgrading and see if that helps.

@pixel-paul
Copy link

We're still seeing the same issue with 2.101:

image

image

@iliajie
Copy link
Contributor

iliajie commented Sep 5, 2023

We're still seeing the same issue with 2.101:

image

image

Webmin .. ? It should be Virtualmin and/or Virtualmin Nginx module.

Although, I agree that the usage is confusing. I will add placeholders for the textfields.

Besides, URL at this website should be like /dir1 .. not domain name ..

@iliajie
Copy link
Contributor

iliajie commented Sep 5, 2023

Next Virtualmin release will have it displayed more explicitly using placeholders, e.g.:

image

@pixel-paul
Copy link

Not sure, Jamie suggested trying 2.101

I tried with a sub directory too (so https://www.example.com/test) and I get the same error.

@iliajie
Copy link
Contributor

iliajie commented Sep 5, 2023

Please look at my screenshot above for reference.

@pixel-paul
Copy link

This is related to redirecting www.example.com to example.com

So do we not need to use the second option, 'URL at this website'?

@iliajie
Copy link
Contributor

iliajie commented Sep 5, 2023

So do we not need to use the second option, 'URL at this website'?

No. Here the example that will work for you right now:

image

However, we have bugs that needs to be fixed before we finally release new Virtualmin and Virtualmin Nginx module.

@pixel-paul
Copy link

pixel-paul commented Nov 29, 2023

SYSTEM INFORMATION
OS type and version Rocky Linux 9.3
Webmin version 2.105
Usermin version 2.005
Virtualmin version 7.8.2  
Theme version 21.09.5
Nginx module 1.20-1
Package updates All installed packages are up to date

This just results in a redirect loop:

image

or this:

image

@pixel-paul
Copy link

Nginx really wants two server blocks to handle the www -> non-www redirect:

https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#server-name-if

https://serverfault.com/a/1139001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants