I'm trying to setup a Nginx Reverse Proxy with SSL Offloading and Caching in front an IIS 10 and WordPress with pretty links, but I'm getting an infinite redirect 301 loop.
My Nginx configuration is almost the same as find in this tutorial, as can be see bellow.
upstream www_iis {
server 10.10.0.10:8001;
server 10.10.0.11:8001;
}
server {
listen 443 ssl;
server_name exemple.com;
ssl_certificate /etc/letsencrypt/live/exemple.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/exemple.com/privkey.pem;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
set $do_not_cache 0;
set $skip_reason "";
set $bypass 0;
if ($remote_addr ~ "^(127.0.0.1)$") {
set $bypass $http_secret_header;
}
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
set $skip_reason Cookie;
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $skip_cache 1;
set $skip_reason URI;
}
location / {
proxy_redirect off;
proxy_cache edge-cache;
proxy_cache_revalidate on;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_bypass $bypass $do_not_cache;
proxy_no_cache $do_not_cache;
proxy_set_header Proxy "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Connection "";
proxy_pass http://www_iis;
}
}
On the IIS side, I only have the pretty links rewrite in web.config.
<rewrite>
<rules>
<rule name="WordPress" enabled="true" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule></rules>
</rewrite>
In WordPress both, WordPress Address (URL) and Site Address (URL), was defined with the external url (https://exemple.com), and no additional changes on WordPress files.
I'm not getting why this behavior is happening, but I'm assuming there is something about the pretty links rewrite, because on IIS Server when I type the local ip address on url I'm redirected to domain.
Please, can someone clarify to me how to solve this? Thanks in advance!