Search code examples
nginxhttp-status-code-404

nginx returns 404 when I visit the URL without www


When visit: www.fxmates.com/ => return 404

visit: https://fxmates.com/ => OK

Here's my Nginx config file:

enter image description here

What's wrong?


Solution

  • There are multiple errors in your code actually:

    Firsty, in the line: enter image description here

    Make it:

    server_name fxmates.com www.fxmates.com;

    Also, remove this line:

    enter image description here It's what causes your nginx webserver to give the user a 404 page each and everytime the user goes to any page on fxmates.com on http://fxmates.com, since in any browser when you type fxmates.com only without https:// the browser defaults to http:// and then the return 404 block pushes 404 to the user's browser.

    And the reason this doesn't effect you when you're directly typing https:// in front because, nginx uses the above server block in the configuration file.


    Hope it helps.