How To Fix Nginx Redirect To Wrong Website Error When There Are Multiple WebSites

I create two websites and in one Nginx server to demo this example. is a real domain with HTTPS enabled. And is a fake domain without enabling HTTPS, then I add the domain to IP mapping record in my local machine’s host file to make it accessible. The website management panel is the BT panel. Below is the local host’s file domain to IP mapping data.

1. Nginx Redirect To Wrong Website Error.

Now we can produce Nginx redirect to wrong website error follow the below steps.

  1. Open a web browser such as Firefox.
  2. Input in the web browser, then you can get website’s index.html page as expected.
  3. We can also run curl command in the command line to get the below result.
    $ curl
    <!doctype html>
        <meta charset="utf-8">
            .container {
                width: 60%;
                margin: 10% auto 0;
                background-color: #f0f0f0;
                padding: 2% 5%;
                border-radius: 10px
            ul {
                padding-left: 20px;
                ul li {
                    line-height: 2.3
            a {
                color: #20a53a
        <div class="container">
  4. Input in a web browser, and then you can find it shows web site’s index page content, it is same with
  5. Run curl command in terminal to get index page as below, we can see the HTTP request has been moved to HTTPS request by Nginx server permanently.
    $ curl
    <head><title>301 Moved Permanently</title></head>
    <center><h1>301 Moved Permanently</h1></center>
  6. Now browse URL in the web browser, and you can find it shows website index page content in the web browser. But the domain address in the web browser URL address text box is not changed ( ).
  7. This is because the domain does not enable HTTPS, so Nginx will pick up a website that enabled HTTPS by domain name alphabetic order and return it’s content.
  8. In this example, only has enabled HTTPS, so when you request with HTTPS protocol, it displays website content.
  9. We can also find this error in the website log file. When we add $host ( to print out request domain ) in log data, we can see all request to is routed to in the log file.
  10. To fix this error, you should enable HTTPS for domain in Nginx, then Nginx can find the domain website when the client request the domain use HTTPS protocol.


  1. How To Install BT VPS Control Panel And Restore WordPress Website Into It
  2. How To Edit Hosts File In Mac OS And Linux, How To Modify Hosts File In Mac
  3. How To Edit Hosts File In Windows 10

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.