Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't open index.php by default with nginx

Tags:

What's wrong with my server definition? If I try to access to "www.testing.com" I get a binary to download instead of the index.php, instead if I try to access to "testing.com" I get the index.php.

I already tried to set servername to:

servername testing.com; servername testing.com www.testing.com; servername testing.com www.testing.com *.testing.com; 

Same behavior: I can't get index.php with "www.testing.com", just with "testing.com". (off course testing.com is not mine is just for example).

    user              nginx;     worker_processes  4;     error_log         /var/log/nginx/error.log warn;     pid               /var/run/nginx.pid;      events {          worker_connections  1024;     }       http {          include      /etc/nginx/mime.types;          default_type  text/plain;           log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                             '$status $body_bytes_sent "$http_referer" '                             '"$http_user_agent" "$http_x_forwarded_for"';           access_log  /var/log/nginx/access.log  main;           fastcgi_intercept_errors    on;          sendfile                    on;          keepalive_timeout           65;          gzip                        on;          index                       index.php index.html index.htm;           server {               listen 80;               server_name www.testing.com;               root /home/vhosts/testing;                location / {                   try_files $uri $uri/ /index.php index.php;               }          location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {                   expires max;                   add_header Pragma public;                   add_header Cache-Control "public, must-revalidate, proxy-revalidate";               }          location ~* \.php$ {                  try_files $uri =404;                  include fastcgi.conf;                  fastcgi_pass  127.0.0.1:9000;               }          }     } 
like image 629
Damiano Barbati Avatar asked Jan 25 '12 11:01

Damiano Barbati


People also ask

Where is the default nginx index HTML?

By default Nginx Web server default location is at /usr/share/nginx/html which is located on the default file system of the Linux.


2 Answers

first you need to check your php-fpm settings (maybe you using socket connection instead of port in your php-fpm configuration) and add index by default in your location "/"

location / {     index index.php index.html index.htm;     try_files $uri $uri/ =404; } 
like image 136
Sergey Nikolaev Avatar answered Oct 06 '22 11:10

Sergey Nikolaev


Add fastcgi_index index.php; in location ~* \.php$:

location ~* \.php$ {     try_files $uri =404;     include fastcgi.conf;     fastcgi_pass  127.0.0.1:9000;     fastcgi_index  index.php; } 
like image 24
Ali Akbar Azizi Avatar answered Oct 06 '22 09:10

Ali Akbar Azizi