You are not logged in.

#1 2014-03-14 17:02:32

infiniphunk
Member
Registered: 2012-08-06
Posts: 30

nginx + php-fpm hell

Hello
I'd love to switch from apache2 running on a Debian Wheezy VM I have to Nginx on Arch (not a VM)

Nginx on it's own works but when I install php and php-fpm it just doesn't work. I get everything from "file not found" errors to "access denied" to:

"An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later."

Now I have tried to follow the Arch wiki on setting this up (except that I didn't set up nginx in chroot -- does it matter?)

I've searched around and tried numerous changes to my nginx.conf file (and yes I restart nginx and php-fpm each time I save it) and it still won't work.

here's my nginx.conf file

#user html;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /srv/http/sites;
            index  index.html index.htm;
      	}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        
	location ~ \.(php|html|htm)$ {
	#fastcgi_pass   unix:var/run/php-fpm/php-fpm.sock;
        fastcgi_pass   127.0.0.1:9000;
      	fastcgi_index  index.php;
	include        fastcgi_params;
 	}

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

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

so far I am finding setting up php to work with nginx to be waaaaaaaay harder than with apache.
Please help

Offline

#2 2014-03-14 17:13:06

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: nginx + php-fpm hell

Show us your php-fpm config too. I'm guessing it isn't configured to listen on 127.0.0.1:9000; which is why the socket is recommended. Also; you could have a look at both the nginx and fpm error-logs if you want to fix this yourself. Also; why haven't you configured a global root?

Try moving one from a location-block to 'server'. If you still have problems you could have a look at https://bbs.archlinux.org/viewtopic.php?id=178203

Last edited by Spider.007 (2014-03-14 17:26:07)

Offline

#3 2014-03-15 22:47:14

infiniphunk
Member
Registered: 2012-08-06
Posts: 30

Re: nginx + php-fpm hell

thanks for the tips! I'll look into it. I've got nginx working with php-fpm nicely on Openbsd I'll also look there at the configs to see if there isn't something I haven't overlooked. smile
I really want to get it going on Arch though because Pacman >> PKG_ADD IMHO

Offline

#4 2014-03-15 23:47:27

infiniphunk
Member
Registered: 2012-08-06
Posts: 30

Re: nginx + php-fpm hell

I put hell in the title because as I tried to fix the issue I would get the various errors, each time, after editing the .conf, restarting nginx and reloading the page. Ah good times.

Offline

#5 2014-03-15 23:47:47

progandy
Member
Registered: 2012-05-17
Posts: 5,201

Re: nginx + php-fpm hell

This is a basic working configuration. (The listen-socket in php-fpm.conf is /run/php-fpm/php-fpm.sock and cgi.fix_pathinfo is on )

    server {
        listen 80;
        server_name localhost;
        root   /srv/http;

        location / {
            autoindex  on;
            index  index.html index.php index.htm;
        }

        location ~ [^/]\.php(/.*)?$ {
            fastcgi_split_path_info ^(.+\.php)(/.*)?$;
            # the if is not really necessary. 
            # php-fpm already checks if the script has a .php extension
            #~ if (!-f $document_root$fastcgi_script_name) {
            #~    return 404;
            #~ }
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$uri;
            fastcgi_param PATH_INFO $fastcgi_path_info if_not_empty;
        }


        location ~ /.ht {
            deny all;
        }

    }

Last edited by progandy (2014-03-15 23:48:38)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2014-03-17 18:45:21

infiniphunk
Member
Registered: 2012-08-06
Posts: 30

Re: nginx + php-fpm hell

thank you for your replies. I thought I had it going on openbsd, but can't seem to get phpMyAdmin going, and even Drupal7 won't go through the setup. somehow some php modules not loading I think..

Offline

Board footer

Powered by FluxBB