Showing posts with label Apache2. Show all posts
Showing posts with label Apache2. Show all posts

Wednesday, 27 August 2025

Apache configuration to listen and server multiple port of same domain, virtualhost *:443 vs virtualhost _default: 443

 # Enable needed modules (once)

# a2enmod ssl proxy proxy_http headers

# (optional for HTTP/2) a2enmod http2


# Tell Apache to listen on both ports

Listen 443

Listen 9888

//!!!!!!!!!!!! the above is usually in httpd.conf

# --- :443 -> https://serverA/ ---

<VirtualHost *:443>

  ServerName testme.com


  SSLEngine On

  # Reuse the same cert for both ports (or different, your choice)

  SSLCertificateFile      /etc/ssl/certs/testme.crt

  SSLCertificateKeyFile   /etc/ssl/private/testme.key

  # SSLCertificateChainFile /etc/ssl/certs/chain.pem   # if needed

  # Protocols h2 http/1.1   # if you use mod_http2


  ProxyPreserveHost On

  SSLProxyEngine On            # because backend is https

  # (Optional if backend is self-signed)

  # SSLProxyVerify none

  # SSLProxyCheckPeerName off

  # SSLProxyCheckPeerExpire off


  ProxyPass        "/"  "https://serverA/"

  ProxyPassReverse "/"  "https://serverA/"

</VirtualHost>


# --- :9888 -> https://serverB:9586/ ---

<VirtualHost *:9888>

  ServerName testme.com


  # If clients connect with https://testme.com:9888 then you MUST enable SSL here too

  SSLEngine On

  SSLCertificateFile      /etc/ssl/certs/testme.crt

  SSLCertificateKeyFile   /etc/ssl/private/testme.key

  # Protocols h2 http/1.1


  ProxyPreserveHost On

  SSLProxyEngine On


  ProxyPass        "/"  "https://serverB:9586/"

  ProxyPassReverse "/"  "https://serverB:9586/"

</VirtualHost>



VirtualHost *:443

  • Means: this vhost will respond on all IPs bound to the server, on port 443.

  • Typical form used in almost all modern Apache configs.

  • Can be matched by ServerName or ServerAlias for name-based virtual hosting.

  • If multiple vhosts on the same port exist, Apache picks the one with the best ServerName match (or the first defined as fallback).

This is the recommended style when you’re hosting multiple domains on the same server/port (which is your case — one domain, two ports).


For same domain multiple ports this is also recommended


VirtualHost _default_:443

  • Means: this vhost is the “catch-all” for port 443 if no other vhost matches.

  • It’s not tied to ServerName or ServerAlias matching — it’s just the fallback.

  • Useful if you want a safety net for requests that don’t match any defined ServerName. For example, sending them to a default “Not Found / Wrong Host” site.

  • Only one _default_ vhost per port can exist.

Wednesday, 13 August 2025

apache notes

 # --- reverse proxy (HTTPS front -> HTTPS backend) ---

ProxyRequests Off

SSLProxyEngine On


# Try first with Off (most apps are happier). If your backend needs the

# original Host, flip it back to On.

ProxyPreserveHost Off


AllowEncodedSlashes NoDecode


# Forward scheme and client IP

RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}

RequestHeader append X-Forwarded-For %{REMOTE_ADDR}e


# IMPORTANT: use ProxyPass (not ProxyPassMatch) and include trailing slashes

# so paths and queries are preserved. "nocanon" avoids re-encoding that can

# trigger 400s on some apps.

ProxyPass        "/"  "https://100.230.50.22:14001/" nocanon retry=0 timeout=5

ProxyPassReverse "/"  "https://100.230.50.22:14001/"


# If you have big cookies (SSO), bump limits to avoid 400 on large headers

#LimitRequestFieldSize 32768






ProxyRequests Off


Meaning: Disables forward proxy mode (where Apache would proxy arbitrary requests to any host requested by the client).


Why: You’re running a reverse proxy for a specific backend, not an open forward proxy.


Impact: Prevents Apache from being abused as an open relay.


SSLProxyEngine On


Meaning: Allows Apache to make HTTPS connections to backends (your upstream server) instead of only HTTP.


Why: Without this, if you try to ProxyPass to an https:// target, Apache will refuse and log:


AH00961: HTTPS proxy requested but SSLProxyEngine disabled



Impact: Enables Apache to negotiate TLS with your backend (https://100.230.50.22:14001/ in your case).


ProxyPreserveHost Off


Meaning: Controls what Host: header Apache sends to the backend.


Off → Apache sends the hostname from your ProxyPass target (100.230.50.22:14001).


On → Apache sends the original hostname from the client request (test.com:14001).


Why: Many apps are picky about the Host header.


If your backend app only responds to its own configured hostname (e.g., its IP or internal FQDN), use Off.


If your backend expects to see the public host (e.g., for virtual hosting, routing, or SSL name matching), use On.


Impact: Choosing the wrong value is a common cause of HTTP 400 from backends.


AllowEncodedSlashes NoDecode


Meaning: Lets Apache pass encoded slashes (%2F) in URLs to the backend without decoding them.


Why:


By default, Apache rejects %2F as potentially unsafe (it treats it like a directory separator).


Some apps need %2F in path segments (e.g., IDs containing slashes, base64 blobs).


Impact: Prevents Apache from rejecting such URLs with a 400 or rewriting them in ways that break the backend.





"/" (no trailing slash on backend)

ProxyPass "/" "https://backend.example.com"



No trailing / on the backend URL means Apache does not insert a / before appending the remainder.


This can produce ugly or broken URLs:


Request: /foo

→ Backend sees: https://backend.example.comfoo (note missing slash)


This is a common cause of HTTP 400 or 404 from the backend.





Quotes around / or the backend URL make no difference here.


Whether the backend URL ends with / does make a difference — it determines how Apache joins the incoming path to the backend path.





You switched from ProxyPassMatch to ProxyPass.

Your old line


ProxyPassMatch / https://100.230.50.22:443/



matches only the leading / and (because there’s no capture like ^(.*)$) can drop or warp the rest of the path. That’s why some URLs turned into “file not found.”

With:


ProxyPass "/" "https://100.230.50.22:443/" ...



Apache does a simple prefix map and preserves the entire remainder of the path.


You added a trailing slash on the backend URL.

Trailing slashes control how Apache concatenates paths:


ProxyPass "/" "https://…/"


/images/logo.png → backend sees /images/logo.png ✅


ProxyPass "/" "https://…" (no slash)


/images/logo.png → backend sees images/logo.png ❌ (missing /)


You kept nocanon, so Apache doesn’t re-encode the URL.

Without nocanon, Apache may re-encode %2F, +, etc., which can break app routing and cause 404/400 on certain endpoints.


So the magic isn’t “https://148.230.50.22:443/ fixed it,” it’s ProxyPass + trailing slash + nocanon that fixed your path preservation.



# each config file need to have log and location mode set 


        # needed

        ErrorLog /usr/local/apache2/custom_log/test.com.error.log

        CustomLog /usr/local/apache2/custom_log/test.com-ssl-443.access.log combined


# # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

# # error, crit, alert, emerg.

# # It is also possible to configure the loglevel for particular

# # modules, e.g.

# #LogLevel info ssl:war

        LogLevel proxy:debug ssl:info




# for every byte log


        # log in error.log

        # only enable every byte log for debugging

        # LoadModule dumpio_module modules/mod_dumpio.so

        # DumpIOInput On

        # DumpIOOutput On

        # LogLevel dumpio:trace7



# special proxy handling for wss(websocket)

        # Keep these modules loaded: proxy, proxy_http, proxy_wstunnel, ssl

        ProxyRequests Off

        SSLProxyEngine On

        # Try first with Off (most apps are happier). If your backend needs the

        # original Host, flip it back to On.

        ProxyPreserveHost On

        AllowEncodedSlashes NoDecode

        RequestHeader set    X-Forwarded-Proto expr=%{REQUEST_SCHEME}

        RequestHeader append X-Forwarded-For   %{REMOTE_ADDR}e


        # Prefer HTTP/1.1 (WS uses Upgrade). Start with h2 disabled to remove that variable:

        Protocols http/1.1


        # Don't silently fall back to HTTP if Upgrade fails

        ProxyWebsocketFallbackToProxyHttp Off


        # If your backend has a proper hostname on its cert, USE IT here (best practice):

        # replace backend.example.com with your backend FQDN that matches its certificate

        # Otherwise keep the IP but read the TLS notes below.


        # Map BOTH forms (no trailing slash, and trailing slash)

        ProxyPass        "/dest/websockify"   "wss://100.230.50.22:443/dest/websockify"   retry=0 timeout=600

        ProxyPassReverse "/dest/websockify"   "wss://100.230.50.22:443/dest/websockify"

        ProxyPass        "/dest/websockify/"  "wss://100.230.50.22:443/dest/websockify/"  retry=0 timeout=600

        ProxyPassReverse "/dest/websockify/"  "wss://100.230.50.22:443/dest/websockify/"


        # --- everything else over HTTPS ---

        ProxyPass        "/"  "https://148.230.50.22:443/" nocanon retry=0 timeout=30

        ProxyPassReverse "/"  "https://148.230.50.22:443/"


Monday, 18 December 2023

Apache how to disable tls1.0, 1.1

test if TLS 1.1, 1.0 is supported:

 https://stackoverflow.com/questions/40557031/command-prompt-to-check-tls-version-required-by-a-host


For TLS 1.2:

openssl s_client -connect www.google.com:443 -tls1_2

For TLS 1.1:

openssl s_client -connect www.google.com:443 -tls1_1

For TLS 1:

openssl s_client -connect www.google.com:443 -tls1


diable 1.0, 1.1 in apache
https://www.ssl.com/guide/disable-tls-1-0-and-1-1-apache-nginx/

go to your sites/my-site-ssl.conf:
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1