2

I've set my nginx but now every *.php file on my virtual host returns 500 internal server error.

server {
listen   tucnak.dev:80; ## listen for ipv4; this line is default and implied

root /home/tucnak/Web/Lab;
index index.php index.html;

server_name tucnak.dev;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ /index.html;
}

location /doc {
    root /usr/share;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}

location /images {
    root /usr/share;
    autoindex off;
}

#error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/www;
}

location ~ \.php$ {
    proxy_pass http://127.0.0.1;
}

location  ~ \.php$ {
        set $php_root /home/tucnak/Web/Lab;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}
}

Where is my error? My php-file is total correct!

 <?php echo("Hello!"); ?>

I am really new at nginx and need help with it. After apache2 - I am confused!

UPD: I think that nginx not successfully gives query for apache. I don't know how to fix it.

6
  • 1
    Why are you using both proxy_pass and fastcgi_pass ? Commented Feb 18, 2012 at 21:43
  • Without it (proxy_pass) he offers my to download .php file) Commented Feb 18, 2012 at 22:03
  • 1
    you probably need to remove one of the locations location ~ \.php$ it is not clear, are you using apache backend or fastcgi. nginx i thinks can not resolve that too Commented Feb 18, 2012 at 22:17
  • I am confused. I've installed nginx and apache2 on new machine. There are no apache2 configs. So, what I have to do? Commented Feb 18, 2012 at 22:19
  • You are getting error 500 because of your ambiguous location. And, without proxy_pass it is downloading your php file because I think your apache does not have fast_cgi enabled. Commented Feb 19, 2012 at 5:04

1 Answer 1

1

I have been googling and testing all the tutorials for distros I came across with and none worked. So I learnt that one must consult the right docs for you distro or it simply will not work. So I have found this one

I have RHE5.7 Tikanga running Apache 2.2. Two sites running on port 8080 and nginx-1.0.14-1.el5.ngx 80. I mean that I have two directories smlinking to /var/www/html/site1 and /var/www/html/site2. Both in php 5.

For those who admin Red Hat sites, this worked for me

  1. Edit http.conf and change to Listen 8080
  2. amend nginx.conf accordinglly as per site instructions.
  3. Amend Virtual hosts file /etc/httpd/conf.d/httpd-vhosts.conf or other so long as it can be included by http.conf include directive as follows:

$ NameVirtualHost *:8080

<VirtualHost *:8080>
    ServerAdmin [email protected]
    ServerName localhost
    DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin [email protected]
    ServerName site1
    DocumentRoot /var/www/html/site1
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin [email protected]
    ServerName site2
    DocumentRoot /var/www/html/site2
</VirtualHost>`

/etc/nginx/nginx.conf - amendments On top of this file:

..... $worker_rlimit_nofile 20480; ....

    gzip_buffers 32 8k;
    gzip_comp_level   6;
    gzip_http_version 1.0;
    gzip_min_length   1;

The line #include /etc/nginx/conf.d/*.conf has been commented as this was useless for me). All the remained code was unchanged but my IP and servername, in this case I put hostname,and the root instruction remained the same the root /usr/share/nginx/html, which is different from the one in virtual conf file /var/www/html/. My guess is that nginx as front-end does not know (and not even should) where the web files to be served are but Apache.

When I go to any browser and type:

ip shows nginx default page, so i guess it is listening to 80 port; ip/site1 displays site1 ip/site2 displays site2

Any other port but 80 or 8080 displays connection error.

regards.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.