{"id":3386,"date":"2024-10-17T15:39:06","date_gmt":"2024-10-17T22:39:06","guid":{"rendered":"https:\/\/spiffynasty.com\/blahblahblah\/?p=3386"},"modified":"2024-10-17T15:39:06","modified_gmt":"2024-10-17T22:39:06","slug":"reverse-proxy-internal-and-external-urls-w-wordpress","status":"publish","type":"post","link":"https:\/\/spiffynasty.com\/blahblahblah\/reverse-proxy-internal-and-external-urls-w-wordpress\/","title":{"rendered":"Reverse Proxy &amp; Internal and External Urls w\/ WordPress"},"content":{"rendered":"<h3 id='how-the-reverse-proxy-handles-http-to-https'>How the Reverse Proxy Handles HTTP to HTTPS<\/h3>\n<p>When you set up a reverse proxy, here\u2019s how it works:<\/p>\n<ol>\n<li>\n<p><strong>External HTTPS Request:<\/strong><\/p>\n<ul>\n<li>A user visits <code>https:\/\/spiffynasty.com\/blahblahblah\/<\/code> (secured with HTTPS).<\/li>\n<li>The reverse proxy (on <code>spiffynasty.com<\/code>) receives this request over HTTPS.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Internal Forwarding to HTTP:<\/strong><\/p>\n<ul>\n<li>The reverse proxy forwards this request internally to your NAS using HTTP, like <code>http:\/\/192.168.1.30\/blahblahblah\/<\/code>.<\/li>\n<li>The connection between <code>spiffynasty.com<\/code> and <code>192.168.1.30<\/code> (your NAS) is happening over your <strong>local network<\/strong>, so it\u2019s secure in the sense that it\u2019s not exposed to the outside world.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Response from NAS:<\/strong><\/p>\n<ul>\n<li>Your NAS (<code>192.168.1.30<\/code>) serves the requested content back to the reverse proxy over HTTP.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Secure Response to the Client:<\/strong><\/p>\n<ul>\n<li>The reverse proxy then encrypts the response (via HTTPS) and sends it back to the user as <code>https:\/\/spiffynasty.com\/blahblahblah\/<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3 id='why-its-safe'>Why It\u2019s Safe:<\/h3>\n<p>The critical point is that the <strong>public-facing<\/strong> side (what users interact with) is over HTTPS, secured by the certificate you set up on <code>spiffynasty.com<\/code>. The internal communication between <code>spiffynasty.com<\/code> and <code>192.168.1.30<\/code> happens over HTTP because:<\/p>\n<ul>\n<li>It\u2019s within your local network (e.g., 192.168.x.x range), which isn\u2019t accessible to the public.<\/li>\n<li>For most local network setups, this is considered secure, as it\u2019s unlikely anyone can snoop on traffic inside your private LAN.<\/li>\n<\/ul>\n<h3 id='key-role-of-the-reverse-proxy'>Key Role of the Reverse Proxy:<\/h3>\n<p>The reverse proxy acts as the &quot;translator&quot;:<\/p>\n<ul>\n<li>It <strong>terminates the SSL<\/strong> (HTTPS) connection, meaning it handles the encryption and decryption for the public-facing side.<\/li>\n<li>It <strong>communicates with your NAS<\/strong> using HTTP, which doesn\u2019t require SSL because it&#39;s inside your private network.<strong><\/strong><\/li>\n<\/ul>\n<h2>Internal and External urls w\/ WordPress<\/h2>\n<p>Using <code>http:\/\/192.168.1.30<\/code> in the WordPress database for the <strong>site URL<\/strong> (both the <code>siteurl<\/code> and <code>home<\/code> options) might seem like a convenient way to ensure the site works locally even if the reverse proxy goes down, but there are a few important considerations and trade-offs:<\/p>\n<h3 id='1-internal-url-vs-external-url'>1. <strong>Internal URL vs. External URL<\/strong><\/h3>\n<p>If you set the <code>siteurl<\/code> and <code>home<\/code> in the WordPress database to <code>http:\/\/192.168.1.30<\/code> (the internal IP of the NAS), WordPress will generate links and assets (like CSS, JavaScript, and images) using this internal IP address, which could cause issues when accessing the site externally via the reverse proxy (<code>https:\/\/spiffynasty.com<\/code>).<\/p>\n<h4 id='why-this-is-a-problem'>Why this is a problem:<\/h4>\n<ul>\n<li><strong>Broken Links for External Visitors<\/strong>: All URLs (like posts, media files, etc.) would point to <code>http:\/\/192.168.1.30<\/code>, which is not accessible from the outside world. Visitors going to <code>https:\/\/spiffynasty.com<\/code> will see these internal links, causing content to fail to load.<\/li>\n<li><strong>Mixed Content Warnings<\/strong>: If your reverse proxy is serving the site over HTTPS, but assets are still loaded from <code>http:\/\/192.168.1.30<\/code> (HTTP), browsers will block these resources or show &quot;mixed content&quot; warnings, making the site appear insecure.<\/li>\n<\/ul>\n<h3 id='2-how-to-handle-local-access'>2. <strong>How to Handle Local Access<\/strong><\/h3>\n<p>There are better ways to ensure that the site works locally and externally without hardcoding <code>http:\/\/192.168.1.30<\/code> into the database:<\/p>\n<h4 id='a-use-spiffynastycom-as-the-site-url'>a. <strong>Use <code>spiffynasty.com<\/code> as the Site URL<\/strong><\/h4>\n<p>Keep <code>https:\/\/spiffynasty.com\/blahblahblah<\/code> in the database as the <strong>site URL<\/strong>. This ensures that all URLs and assets are correctly served for external visitors, but also works fine for local access through the reverse proxy.<\/p>\n<p>When you access the site locally via <code>http:\/\/192.168.1.30<\/code>, the reverse proxy can still forward requests correctly, so your site will load as expected, with the links pointing to <code>spiffynasty.com<\/code>. Since the NAS serves the content locally, it will work.<\/p>\n<h4 id='b-use-a-conditional-in-wp-configphp-for-local-and-external-access'>b. <strong>Use a Conditional in <code>wp-config.php<\/code> for Local and External Access<\/strong><\/h4>\n<p>You can set up WordPress to detect whether you&#39;re accessing it locally or through the reverse proxy and adjust the site URL accordingly. Here&#39;s how:<\/p>\n<p>In <code>wp-config.php<\/code>, add a conditional statement like this:<\/p>\n<pre><code class=\"language-javascript\">\r\nif ($_SERVER[&#39;REMOTE_ADDR&#39;] == &#39;192.168.1.30&#39;) {\r\n    define(&#39;WP_HOME&#39;, &#39;http:\/\/192.168.1.30\/blahblahblah&#39;);\r\n    define(&#39;WP_SITEURL&#39;, &#39;http:\/\/192.168.1.30\/blahblahblah&#39;);\r\n} else {\r\n    define(&#39;WP_HOME&#39;, &#39;https:\/\/spiffynasty.com\/blahblahblah&#39;);\r\n    define(&#39;WP_SITEURL&#39;, &#39;https:\/\/spiffynasty.com\/blahblahblah&#39;);\r\n}\r\n<\/code><\/pre>\n<p>This way, if you&#39;re accessing the site from the local network, WordPress will use <code>http:\/\/192.168.1.30<\/code>, and if you&#39;re accessing it from anywhere else, it will use the public <code>https:\/\/spiffynasty.com<\/code> URL.<\/p>\n<h3 id='3-handling-media-and-assets'>3. <strong>Handling Media and Assets<\/strong><\/h3>\n<p>One potential issue with switching URLs dynamically is that WordPress stores absolute URLs for media files in the database. If you use the internal IP (<code>192.168.1.30<\/code>), media links will be stored using this address, which can cause broken links when accessing the site externally.<\/p>\n<p>To avoid this:<\/p>\n<ul>\n<li>Keep the site URLs as the public-facing ones (e.g., <code>https:\/\/spiffynasty.com<\/code>).<\/li>\n<li>Access the site locally through the reverse proxy as much as possible.<\/li>\n<\/ul>\n<h3 id='4-database-considerations'>4. <strong>Database Considerations<\/strong><\/h3>\n<p>If you decide to switch the URLs between local\/internal and external, you may also need to replace URLs in the database whenever you change the setup (for example, using search-and-replace tools like <strong>Better Search Replace<\/strong>). This isn&#39;t ideal for dynamic environments where both internal and external access is required regularly.<\/p>\n<h3 id='conclusion'>Conclusion<\/h3>\n<p>It\u2019s generally best to keep the <strong>public-facing URL<\/strong> (<code>https:\/\/spiffynasty.com<\/code>) as the site URL in the WordPress database. This avoids external visitors encountering issues with internal IPs and ensures proper SSL and link handling.<\/p>\n<p>However, you can use conditionals in <code>wp-config.php<\/code> to allow for local access using <code>http:\/\/192.168.1.30<\/code> if needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How the Reverse Proxy Handles HTTP to HTTPS When you set up a reverse proxy, here\u2019s how it works: External HTTPS Request: A user visits https:\/\/spiffynasty.com\/blahblahblah\/ (secured with HTTPS). The reverse proxy (on spiffynasty.com) receives this request over HTTPS. Internal Forwarding to HTTP: The reverse proxy forwards this request internally to your NAS using HTTP, like http:\/\/192.168.1.30\/blahblahblah\/. The connection between spiffynasty.com and 192.168.1.30 (your NAS) is happening over your local network, so it\u2019s secure in the sense that it\u2019s not exposed to the outside world. Response from NAS: Your NAS (192.168.1.30) serves the requested content back to the reverse proxy over HTTP. Secure Response to the Client: The reverse proxy then encrypts the response (via HTTPS) and sends it back to the user as https:\/\/spiffynasty.com\/blahblahblah\/. Why It\u2019s Safe: The critical point is that the public-facing side (what users interact with) is over HTTPS, secured by the certificate you set up on spiffynasty.com. The internal communication [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[65,27],"tags":[],"class_list":["post-3386","post","type-post","status-publish","format-standard","hentry","category-frontpage","category-nas"],"_links":{"self":[{"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/posts\/3386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/comments?post=3386"}],"version-history":[{"count":1,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/posts\/3386\/revisions"}],"predecessor-version":[{"id":3387,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/posts\/3386\/revisions\/3387"}],"wp:attachment":[{"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/media?parent=3386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/categories?post=3386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spiffynasty.com\/blahblahblah\/wp-json\/wp\/v2\/tags?post=3386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}