apache - Apache2 https redirect work but http redirect to local ip address - Stack Overflow

admin2025-04-17  3

I have an apache2 web server working great, today I added a subdomain redirect for my other services (jellyfin as an example)

The jellyfin redirection functions very well, jellyfin works on port 8096 on another IP address and when I type jelly.mydomain.fr it redirects well

Next, I have a proxmox instance I want to be redirected to, to access it in local I have to type https://IpAddress:8006 (nothing new here). Now I have set the proxmox.mydomain.conf files for both port 80 and 443 to redirect to https://IpAddress:8006 Now when I type it works well but when I do proxmox.mydomain.fr it redirects me to the local IP address which obviously does not work when not on the same network

proxmox.mydomain.fr.conf :

#<VirtualHost *:80>
#    ServerName proxmox.mydomain.fr
#
#     Rediriger toutes les requêtes HTTP vers l'URL HTTPS externe
#    RewriteEngine On
#    RewriteRule ^(.*)$ https://IpAddress:8006$1 [L,R=301]

#    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
#    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
#</VirtualHost>

<VirtualHost *:80>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    # Rediriger toutes les requêtes HTTP vers HTTPS sur le même domaine
    Redirect permanent / /

    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
</VirtualHost>

I have tried with the commented text to redirect with the rewriteEngine directive but did not work with both the domain name and IP address

proxmox.mydomain.fr-ssl.conf :

<VirtualHost *:443>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/proxmox.mydomain.fr/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/proxmox.mydomain.fr/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    ProxyPreserveHost On
    ProxyPass / https://IpAddress:8006/
    ProxyPassReverse / https://IpAddress:8006/

    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
</VirtualHost>

I tried with both rewriteEngine and Redirect directive, with the domain name or ip address but none seemed to work

The goal of the maneuver is to access the https resource by only typing proxmox.mydomain.fr, it works for some of my other services (in http) for proxmox only when typing https it works, I was hoping I could redirect the http request to the domain name and not the IP address

I haven't found any topic relating to this issue, maybe I don't know how to search

I have an apache2 web server working great, today I added a subdomain redirect for my other services (jellyfin as an example)

The jellyfin redirection functions very well, jellyfin works on port 8096 on another IP address and when I type jelly.mydomain.fr it redirects well

Next, I have a proxmox instance I want to be redirected to, to access it in local I have to type https://IpAddress:8006 (nothing new here). Now I have set the proxmox.mydomain.conf files for both port 80 and 443 to redirect to https://IpAddress:8006 Now when I type https://proxmox.mydomain.fr it works well but when I do proxmox.mydomain.fr it redirects me to the local IP address which obviously does not work when not on the same network

proxmox.mydomain.fr.conf :

#<VirtualHost *:80>
#    ServerName proxmox.mydomain.fr
#
#     Rediriger toutes les requêtes HTTP vers l'URL HTTPS externe
#    RewriteEngine On
#    RewriteRule ^(.*)$ https://IpAddress:8006$1 [L,R=301]

#    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
#    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
#</VirtualHost>

<VirtualHost *:80>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    # Rediriger toutes les requêtes HTTP vers HTTPS sur le même domaine
    Redirect permanent / https://proxmox.mydomain.fr/

    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
</VirtualHost>

I have tried with the commented text to redirect with the rewriteEngine directive but did not work with both the domain name and IP address

proxmox.mydomain.fr-ssl.conf :

<VirtualHost *:443>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/proxmox.mydomain.fr/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/proxmox.mydomain.fr/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    ProxyPreserveHost On
    ProxyPass / https://IpAddress:8006/
    ProxyPassReverse / https://IpAddress:8006/

    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
</VirtualHost>

I tried with both rewriteEngine and Redirect directive, with the domain name or ip address but none seemed to work

The goal of the maneuver is to access the https resource by only typing proxmox.mydomain.fr, it works for some of my other services (in http) for proxmox only when typing https it works, I was hoping I could redirect the http request to the domain name and not the IP address

I haven't found any topic relating to this issue, maybe I don't know how to search

Share edited Feb 4 at 6:49 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Feb 1 at 17:03 Josselin MathieuJosselin Mathieu 111 bronze badge 2
  • Sound like an issue with local caching to me, actually. You did test using a fresh anonymous browser, didn't you? – arkascha Commented Feb 2 at 7:32
  • Yes, I Tried by using another computer in rdp that I hadn't use at the moment – Josselin Mathieu Commented Feb 2 at 11:33
Add a comment  | 

1 Answer 1

Reset to default 0

With my naked eye I don't see any errors in your configuration, maybe you should make sure the apache config is reloaded (service apache2 reload or similar command)

<VirtualHost *:80>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    Redirect permanent / https://proxmox.mydomain.fr/
</VirtualHost>

<VirtualHost *:443>
    ServerName proxmox.mydomain.fr
    ServerAlias www.proxmox.mydomain.fr

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/proxmox.mydomain.fr/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/proxmox.mydomain.fr/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    ProxyPreserveHost On
    ProxyPass / https://IpAddress:8006/
    ProxyPassReverse / https://IpAddress:8006/

    ErrorLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-error.log
    CustomLog ${APACHE_LOG_DIR}/proxmox.mydomain.fr-access.log combined
</VirtualHost>

转载请注明原文地址:http://anycun.com/QandA/1744822625a88100.html