0

Dears

I try to deploy wordpress on amazon ec2, I am facing the trouble on nginx and php-fpm, thanks for your help in advance. I got the error as the following when nginx and php-fpm are running.

[error] 16282#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, 

But if I stop php-fpm, and use "php-cgi -b 9000" instead, it works fine. I have another question is how to debug the issue on nginx and php-fpm, it throws little error message in the log files even I set log level to debug or info. Looking forward to get your response. Thanks a lot.

The following is my configue files.

/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  127.0.0.1;
    root /usr/www/ROOT/wordpress;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;


    #location ~ \.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js|txt)$ {
    #    root /usr/www/ROOT/wordpress;
    #    expires 24h;
    #}

    location / {
    #    root   /usr/www/ROOT/wordpress;
        index  index.php 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$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    #location / {
    #   proxy_pass http://127.0.0.1:8080;
    #}


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

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

part of the config in /etc/php-fpm.d/www.conf

; Start a new pool named 'www'.
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: -1
;listen.backlog = -1

; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. 
; Default Values: user and group are set as the running user
;                 mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache
  • I have a feeling that you have SCRIPT_FILENAME declared in fastcgi_params file as well and it doesn't point to the right location. Or apache user does not have permissions to access those files. Try using runusuer and run php-cgi -b 9000 as apache. – Florin Asăvoaie Sep 7 '14 at 10:15
  • Are the parent directories of your directory readable and traversable? – Michael Hampton Sep 7 '14 at 14:03
  • Thank a lot for your response, very kind of you. I tried to run php-cgi as apache, it works again. And it did not declare SCRIPT_FILENAME in fastcgi_params file, the file is the default one. – lunaseakyo Sep 7 '14 at 14:49
  • To Michael: Thanks. I have rudely run "chmod 777 -R" to the root of wordpress directory. – lunaseakyo Sep 7 '14 at 14:51
0

You are defining the extra fastcgi_param lines before including fastcgi_params file. This means that fastcgi_params defines will override the ones you define here.

So, move include fastcgi_params before fastcgi_param lines.

  • Thanks. I tried your way, but it did not work. It works if I use "php-cgi -b 9000".... So I guess the issue is on php-fpm side. – lunaseakyo Sep 8 '14 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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