virtualmin / virtualmin-nginx

Virtualmin plugin to allow use of nginx web server for virtual domain hosting
GNU General Public License v3.0
36 stars 13 forks source link

HTTPS Redirect not working on Nginx #6

Open jonyoi opened 6 years ago

jonyoi commented 6 years ago

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 commented 6 years ago

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 commented 1 year ago

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 commented 1 year ago

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

pixel-paul commented 1 year ago

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 commented 1 year ago

The source URL path should be just /

pixel-paul commented 1 year ago

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

image

jcameron commented 1 year ago

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

pixel-paul commented 1 year ago

Yes:

Screen Shot 2023-07-21 at 09 31 16

jcameron commented 1 year ago

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

pixel-paul commented 1 year ago
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 commented 1 year ago

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

pixel-paul commented 1 year ago

We're still seeing the same issue with 2.101:

image

image

iliajie commented 1 year ago

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 commented 1 year ago

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

image
pixel-paul commented 1 year ago

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 commented 1 year ago

Please look at my screenshot above for reference.

pixel-paul commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago
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 commented 11 months ago

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