Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've been searching around but couldn't find a straight answer, if someone could please clarify this, would be greatly appreciated, thanks!

location ~ \.php$ {
    try_files      $uri = 404;
    fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi.conf;
}

OR/AND?

upstream php {
    server         unix:/run/php-fpm/php-fpm.sock;
}

Thanks!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

location is used to match expressions and create rules for them

upstream defines servers that can be referenced to.

In your example this means if you want to get an equivalent for

location ~ \.php$ {
    try_files      $uri = 404;
    fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi.conf;
}

, you would need

upstream php {
    server         unix:/run/php-fpm/php-fpm.sock;
}
location ~ \.php$ {
    try_files      $uri = 404;
    fastcgi_pass   http://php
    fastcgi_index  index.php;
    include        fastcgi.conf;
}

The benefit of the upstream block is that you can configure more than one server/port/service as upstream and distribute the traffic on them, for example like this:

upstream php {
    server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;
    server 192.68.1.2     weight=5;
    server         unix:/run/php-fpm/php-fpm.sock;
}

You can find more information about this here:

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

share|improve this answer
    
Do you nee ip_hash for PHP? What about keepalive? –  CMCDragonkai Apr 15 at 3:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.