Score:1

ProxyPass and ProxyPassReverse causing 500 error on server

in flag

We have the following:

  • WordPress static website at https://www.domain1.com.
  • React/Django Web application at https://www.domain2.com with three main URIs:
    • /
    • /admin
    • /api

We would like them to appear like they are the same domain at https://www.domain1.com. I was told this could be done by setting up a Reverse Proxy on the Apache web server that is at https://www.domain1.com. Due to this we'd have to migrate the current / of https://www.domain2.com, to /portal or /dashboard, which is no problem.

What should happen is if there is a link to https://www.domain1.com/portal/*, it will serve https://www.domain2.com/portal/*, but will still say https://www.domain1.com/portal/* in the browser. Thus, it looks like the same website to the user even though it is coming from the other domain.

Anyway, so I'm attempting to modify the .htaccess for https://www.domain1.com/ by adding the following to the top:

ProxyPass "/portal" "https://www.domain2.com/portal"
ProxyPassReverse "/portal" "https://www.domain2.com/portal"

# or just 

ProxyPass "/portal" "https://www.domain2.com/"
ProxyPassReverse "/portal" "https://www.domain2.com/"

This causes a 500 error on the entire WordPress website.

This is the entirety of the .htaccess:

ProxyPass "/portal" "https://www.domain2.com/portal"
ProxyPassReverse "/portal" "https://www.domain2.com/portal"

# BEGIN WpFastestCache
# Modified Time: 09-09-21 9:26:57
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www.domain1.com
# Start WPFC Exclude
# End WPFC Exclude
# Start_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\[email protected]
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=ad,om
# End_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP_HOST} ^www.domain1.com
RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|WP_FASTEST_CACHE_CSS_VALIDATOR|Twitterbot|LinkedInBot|WhatsApp|Mediatoolkitbot)
RewriteCond %{HTTP_USER_AGENT} !(WP\sFastest\sCache\sPreload(\siPhone\sMobile)?\s*Bot)
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !(\/){2}$
RewriteCond %{REQUEST_URI} ![^\/]+\/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond %{HTTP:Cookie} !comment_author_
RewriteCond %{HTTP:Cookie} !safirmobilswitcher=mobil
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
RewriteCond /nfs/c09/h02/mnt/135490/domains/domain1.com/html/wp-content/cache/all/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
</IfModule>
<FilesMatch "index\.(html|htm)$">
AddDefaultCharset UTF-8
<ifModule mod_headers.c>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
</ifModule>
</FilesMatch>
# END WpFastestCache
# BEGIN GzipWpFastestCache
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddType x-font/ttf .ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE x-font/ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
# END GzipWpFastestCache
# BEGIN LBCWpFastestCache
<FilesMatch "\.(webm|ogg|mp4|ico|pdf|flv|avif|jpg|jpeg|png|gif|webp|js|css|swf|x-html|css|xml|js|woff|woff2|otf|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
AddType application/font-woff2 .woff2
AddType application/x-font-opentype .otf
ExpiresActive On
ExpiresDefault A0
ExpiresByType video/webm A10368000
ExpiresByType video/ogg A10368000
ExpiresByType video/mp4 A10368000
ExpiresByType image/avif A10368000
ExpiresByType image/webp A10368000
ExpiresByType image/gif A10368000
ExpiresByType image/png A10368000
ExpiresByType image/jpg A10368000
ExpiresByType image/jpeg A10368000
ExpiresByType image/ico A10368000
ExpiresByType image/svg+xml A10368000
ExpiresByType text/css A10368000
ExpiresByType text/javascript A10368000
ExpiresByType application/javascript A10368000
ExpiresByType application/x-javascript A10368000
ExpiresByType application/font-woff2 A10368000
ExpiresByType application/x-font-opentype A10368000
ExpiresByType application/x-font-truetype A10368000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=A10368000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache


# Redirect permanent / https://www.domain1.com
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

What am I screwing up here?

kz flag
It's not clear why you would need to change the URL at `domain2.com` to `/portal` as well? `/portal` is presumably just to distinguish the URL to proxy at `domain1.com`?
cjones avatar
in flag
@MrWhite After posting this and looking at the documentation again, it looks like there isn't any reason I couldn't just do `ProxyPass "/portal" "https://www.domain2.com/"`.
kz flag
...Yes, exactly.
kz flag
...except you have a mismatch of trailing slashes in that particular directive. It should be `ProxyPass /portal/ https://www.domain2.com/` - otherwise, you'll end up with a double slash at the start of the URL-path on the proxied request.
Score:2
in flag

ProxyPass is not allowed in a .htaccess file. You need to put it directly in the Apache config.

Context: server config, virtual host, directory

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.