LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Default NGINX Page (https://www.linuxquestions.org/questions/linux-server-73/default-nginx-page-4175445248/)

Rafael25 01-12-2013 04:51 AM

Default NGINX Page
 
Hi,

I have installed NGINX on CentOS 5.x and its working smooth. However if I access mydomain.com in the browser, it throws a 404 error.

What I need to accomplish is :
1) If I access mydomain.com , it should fetch for a default index.php or index.html in the directory allocated(root directory) for that domain and display the same. If there is no such file, then it should display a default custom page(i.e a Welcome Page).

2) If I access mydomain.com/test.php and if test.php is not found only then it should display the 404 error page.

3) Also, I want a common error handler for all the server blocks created(for each domains).

I need the configurations for the same. Any help is greatly appreciated.

rmacd 01-15-2013 08:03 AM

Just an initial thought, I'm sure you know nginx will not do a great deal with a php file on its own, unless you've set up eg FastCGI somewhere for nginx to connect to.

Out of interest, what brought you to choose nginx over, say, Apache? It's not to say it's a great tool, it just sounds like messing with configs (ie to say, getting others to write them for you) might not be quite what you're looking for at the moment. Regardless...

For 1) I would set up a server block which catches all, sticks it in a regex and looks for the site directory:

Code:

server {
    server_name  ~^(www\.)?(?<domain>.+)$;

    location / {
        root  /path/to/$domain;
        index index.html index.php;

        ...

    }
}

2) If there's no test.php it's going to return as a 404 anyway...

3) For all server blocks/for each domain - rather ambiguous - are you wanting to serve up exactly the same error page across all domains? If so take a look at error_page in nginx wiki, there are a couple of solutions you could use.

Rafael25 01-21-2013 01:14 AM

Thanks a lot.. It helped me a lot.

rewards 01-21-2013 02:04 PM

Hello,

I have the same problem. Can you please tell me in details what you have done step by step? Which files you edited and where they are located? Thanks


All times are GMT -5. The time now is 10:13 AM.