nginx + php-fpm ERROR 'FastCGI sent in stderr: "Primary script unknown"' for 2nd app (WP) in a subdir. Main site is OK.

aclion at yepmail.net aclion at yepmail.net
Sun Apr 29 21:48:34 UTC 2018


Hi,

I'm trying to set up WordPress in a subdir on an Nginx+PHPFPM setup.

I'm running

  nginx/1.14.0
  PHP 7.2.4-dev (fpm-fcgi)
  wordpress/4.9.5

The skeleton I have so far is

	tree -L 3 .
	.
	├── includes
	│   └── front.inc
	├── public
	│   ├── css
	│   │   ├── global.css
	│   │   └── min
	│   └── index.php
	└── wp
	    ├── composer.json
	    ├── composer.lock
	    ├── public
	    │   ├── blog
	    │   ├── content
	    │   ├── index.php
	    │   └── wp-config.php
	    ├── README.md
	    └── vendor
	        ├── autoload.php
	        ├── composer
	        └── johnpbloch

WP was populated into the tree using Composer

My Nginx web config includes

	server {

		root /src/www/test/public;
		index index.php;

		rewrite_log on;
		access_log  /var/log/nginx/test.example.com.access.log main;
		error_log   /var/log/nginx/test.example.com.error.log error;


		ssl on;
		ssl_verify_client off;
		include includes/ssl_protocol.inc;
		ssl_trusted_certificate   "ssldir/myCA.crt.pem";
		ssl_certificate           "ssldir/test.example.com.crt.pem";
		ssl_certificate_key       "ssldir/test.example.com.key.pem";

		location ~* /(\.|~$) { deny all; }
		location ~* (settings.php|schema|htpasswd|password|config) { deny all; }
		location ~* .(inc|rb|json)$ { deny all; }

		location ^~ /blog {
			alias /src/www/test/wp/public/blog;
			index index.php;

			try_files $uri $uri/ /index.php$is_args$args;
	#		try_files $uri $uri/ /index.php?$args =404;

			location ~ \.php$ {
				fastcgi_split_path_info ^(.+?\.php)(/.*)$;
				fastcgi_param HTTP_PROXY "";
				fastcgi_pass phpfpm;
				fastcgi_index index.php;
				include includes/fastcgi/fastcgi_params;
			}
		}

		location ~ [^/]\.php(/|$) {
			fastcgi_split_path_info ^(.+?\.php)(/.*)$;
			if (!-f $document_root$fastcgi_script_name) {
				return 404;
			}
			fastcgi_param HTTP_PROXY "";
			fastcgi_pass phpfpm;
			fastcgi_index index.php;
			include includes/fastcgi/fastcgi_params;
		}
		...
	}

and

	grep -i script includes/fastcgi/fastcgi_params 
		fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
		fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

With that config visiting the TOP level of my site

	https://test.example.com/

works like it should.

But visiting the WP app in the /blog subdir alias

	https://test.example.com/blog/

shows these errors in log


	==> /var/log/nginx/test.example.com.error.log <==
	2018/04/29 13:10:16 [error] 6374#6374: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.30.11.7, server: test.example.com, request: "GET /blog/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "test.example.com"

	==> /var/log/nginx/test.example.com.access.log <==
	172.30.11.7 test.example.com - [29/Apr/2018:13:10:16 -0700] GET /blog/ HTTP/2.0 "404" 20 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"

I _think_ that the problem might be that I have to have a different SCRIPT_FILENAME for the WP part of this.

Not sure IF that's the problem, or what to change it TO.

Any help?

Thanks,

AC





More information about the nginx mailing list