• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue Nginx as reverse proxy: loading main domain instead of subdomain

B_P

Regular Pleskian
Dear all,

on my server (18.0.30, Ubuntu 16.04, Plesk+NGINX+Apache, HTTP2) I just created a new subdomain (demo.subscription2.me) that belongs to the second subcription of the admin user and wanted to create a test installation of moodle. However, I do face a problem (despite of using Moodle or not):
When trying to access any page on demo.subscription2.me, Nginx/Apache randomly decide to deliver the content belonging to the default host (myserver.com). I created a simple demo.php file which only runs phpinfo().
I tried to reconfigure the whole webserver configuration already, but the problem remains.

Interestingly, when trying to access https://demo.subscription2.me/demo.php, every now and then, Nginx seems to reply with a 404 error:
Code:
HTTP/2 404 Not Found
server: nginx
date: Wed, 30 Sep 2020 20:09:36 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: PHP/7.3.22
expires: Wed, 11 Jan 1984 05:00:00 GMT
cache-control: no-cache, must-revalidate, max-age=0
link: <https://myserver.com/wp-json/>; rel="https://api.w.org/"
content-encoding: gzip
X-Firefox-Spdy: h2

Similarly, when Moodle is installed on a subdomain, I get the following response:
Code:
HTTP/2 301 Moved Permanently
server: nginx
date: Wed, 30 Sep 2020 20:23:31 GMT
content-type: text/html; charset=UTF-8
content-length: 0
x-powered-by: PHP/7.3.22
x-redirect-by: WordPress
location: https://www.myserver.com/
cache-control: max-age=0
expires: Wed, 30 Sep 2020 20:23:31 GMT
x-powered-by: PleskLin
X-Firefox-Spdy: h2

So I wonder
a) why Nginx does not find the file and
b) how this weird response, containing the link header is given.

It seems that the wrong page is being served, as the 404 response indicates PHP 7.3 is used while the new subdomain useds PHP 7.4.

I did not observe a similar behavior with other (sub)domains yet, but when trying to create another new subdomain, the same seems to happen.
 
Update: Once I disable Nginx, the error disappears (however I would only consider this a temporary workaround).
 
- Check the .htaccess files of the sites thoroughly for unwanted rewrites of URLs. Many a times you'll find a rewrite between very similar looking domains or from http to https or vice versa.
- If we're talking about Wordpress websites, check the siteurl and homepage datasets of the wp_options table that they correspond exactly to the domain the installation is on.
 
- Check the .htaccess files of the sites thoroughly for unwanted rewrites of URLs. Many a times you'll find a rewrite between very similar looking domains or from http to https or vice versa.
- If we're talking about Wordpress websites, check the siteurl and homepage datasets of the wp_options table that they correspond exactly to the domain the installation is on.

I created a fresh domain with only one php file (phpinfo) in its root directory. So no .htaccess or alike.
 
That is inconsistent with your first post. There you presented the headers that were showing that the redirect is coming from a Wordpress installation:
...
x-redirect-by: WordPress
...

Have you checked that siteurl and homepage datasets in your *_options table exactly match the URL that you open when trying to access the site? Else Wordpress will cause the redirect.
 
P.S.: What might be happening is that you have nested domains, meaning that for example you have one domain in /httpdocs, but then added additional domains deriving from httpdocs. In that case rewrite settings of the superior domain will cause issues to all domains located on lower directory levels under httpdocs.
 
Hi Peter,

That is inconsistent with your first post. There you presented the headers that were showing that the redirect is coming from a Wordpress installation:
...
x-redirect-by: WordPress
...

Have you checked that siteurl and homepage datasets in your *_options table exactly match the URL that you open when trying to access the site? Else Wordpress will cause the redirect.
yes this was the scary thing: The two domains where I had this issue do not use Wordpress.

P.S.: What might be happening is that you have nested domains, meaning that for example you have one domain in /httpdocs, but then added additional domains deriving from httpdocs. In that case rewrite settings of the superior domain will cause issues to all domains located on lower directory levels under httpdocs.
Unfortunately, also this was not the case. All domains and subdomains for this subscription have different docroots and they are all on the same lavel relative to the main folder (e.g. /var/www/vhosts/username/domain_a, /var/www/vhosts/username/domain_b, /var/www/vhosts/username/subdomain_a_1).

Interestingly, while I switched off and on nginx last week, the error was again present after I re-enabled nginx. Obviously, I switch to all-Apache then. When I re-enabled nginx today, the problem seems to have disappeared for now.
 
Were there Wordpress installations on these domains previously? Could it be that Nginx was still having something in its cache?
 
Last edited:
I have exactly same problem. When I switch-off Proxy Mode, all problems gone. But I would like to use Nginx and Apache together. So I really don’t know how can I solve this.
 
Once again: Please make sure that Nginx cache is empty. You can empty the cache with the "Clear cache" button in "Apache & Nginx settings" in your subscription.
 
Once again: Please make sure that Nginx cache is empty. You can empty the cache with the "Clear cache" button in "Apache & Nginx settings" in your subscription.
Clearing the cache does not work. It's really strange that any domain redirects to the main domain (full hostname) when I turn on nginx Proxy mode.

Btw if you want to clear the cache under the "Apache & Nginx settings", you need to turn on the "Enable nginx caching" settings. Even though I turned to cache on and cleared the cache, still it does not work.

Do you have any other idea why Plesk behaves strangely?
 
Back
Top