Need Help Configuring Nginx to run Wordpress

I run Wordpress 2.5 under Apache 2.2 on a RedHat 5 ES server with no
problems, and use Nginx to serve images, but I can’t seem to get the
right configuration to run Wordpress under Nginx. I have a script that
runs the launches /usr/bin/spawn-fcgi on localhost IP 127.0.0.1 using
port 8437, and running a process as php-cgi.

Once I switch over Wordpress to Nginx I can view and interact with the
Wordpress control panel, which means PHP is working fine, but I can’t
view the web site home page, or any articles. I get a grey blank page,
not even a 404 error. I am unable to figure this out without help. My
configuration is below.

server {
    listen       my-ip-address:80;
    server_name  www.mydomain.com mydomain.com;

    location / {
    root    /var/www/mydomain;
    index  index.php index.html index.htm;

    if (!-e $request_filename) {
        rewrite ^(.+)$ /index.php?q=$1 last;
     }
    error_page  404              http://www.mydomain.com/e404.php;
}

location ~ .php$ {
fastcgi_pass 127.0.0.1:8437;
fastcgi_index index.php;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME
/var/www/mydomain$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_param REDIRECT_STATUS 200;

 }

One additional note, I don’t use wp-cache, or Supercache, to cache pages
into html files. I just use the straight php.

  1. stop using spawn-fcgi. it sucks. use php-fpm. that’s not the fix to
    your issue, but it is something i recommend. :slight_smile:

here is my (working) nginx conf for wordpress (with friendly URLs
enabled)

the actual wordpress install is hosted in /wordpress, but the urls are
all /2008/etc/ and such off the root.

server {
listen 80;
server_name michaelshadle.com www.michaelshadle.com;
index index.php;
root /home/mike/web/michaelshadle.com/;
location ~ .php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass 127.0.0.1:11000;
fastcgi_index index.php;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /wordpress/index.php?q=$1 last;
}
}

fastcgi.conf:

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

What version of Nginx are you using?

Thanks for the tip on php-fpm Mike I’ll give it a whirl.

I seem to recall errors at 0.5.35 with this rewrite:

rewrite ^(.+)$ /index.php?q=$1 last;

Instead try:

rewrite ^(.*)$ /index.php?q=$1 last;

If you upgrade to 0.6.29 you shouldn’t have any issues with the
original rewrite. Many high traffic sites are using 0.6.29 -
including wordpress.com.

HonDev D. wrote:

What version of Nginx are you using?

Thanks for the tip on php-fpm Mike I’ll give it a whirl.

nginx 0.5.35

mercoledì 23 aprile 2008, mike ha scritto:

  1. stop using spawn-fcgi. it sucks. use php-fpm. that’s not the fix to
    your issue, but it is something i recommend. :slight_smile:

It would be useful if you elaborate why is sucks. Otherwise your
argument
falls short. I’ve tried to browse a bit for some documentation, but it’s
only
in russian.

In my experience:

It ignores the PHP_FCGI_MAX_REQUESTS completely
It didn’t kill the children properly

Running php-fpm is the best, it’s “done right”

2nd best - just set the two PHP_FCGI* vars and use “sudo -u $user
php-cgi -b $port” - it actually recycles the engines properly. I see
absolutely NO need for some extra thing. I set up my php engines in
Ubuntu upstart files. You could use init too, if you wanted. To ensure
it’s running at boot… or do something else.

You’d have to do the same with spawn-fcgi anyway.,

mike wrote:

In my experience:

Mike, which version of Nginx are you using?

wordpress 2.3.x or whatever (haven’t upgraded to 2.5 yet)
nginx 0.6.29

if it’s a blank page, do you have anything in your error logs? turn on
php error reporting, sometimes it loads an empty page if there’s an
error before output it seems.

is it empty, or is there html source? it might be that the page needs
“<?php” to start (that was another issue someone had just yesterday) -
perhaps short_tags is off, and since WP has a lot of mixed code, that
specific page doesn’t have it?

mike wrote:

wordpress 2.3.x or whatever (haven’t upgraded to 2.5 yet)
nginx 0.6.29

if it’s a blank page, do you have anything in your error logs? turn on
php error reporting, sometimes it loads an empty page if there’s an
error before output it seems.

is it empty, or is there html source? it might be that the page needs
“<?php” to start (that was another issue someone had just yesterday) -
perhaps short_tags is off, and since WP has a lot of mixed code, that
specific page doesn’t have it?

short_open_tag = On

Because nothing else is jumping out at me I thought I’d entertain your
suggestion, so I switched to the default theme that comes with Wordpress
2.5, and ran into exactly the same issue as before. I’ve checked every
tag, and they are all correct. I know because I wrote every line of my
own theme, and the default wordpress theme appears to be correct as
well.

In my opinion, if Nginx doesn’t have a tutorial clearly explaining how
to configure and use Nginx with Wordpress, which is the number one blog
script software in the world, then Nginx isn’t ready for prime time.
Nginx won’t be widely accepted and used until it’s Wordpress friendly
with a proper tutorial, and support. I would love to write it and post
it on my tech site, but I can’t seem to even solve my own issue, and no
one appears to be able to help.

Nginx either works with Wordpress or it doesn’t. That’s not very
friendly, or practical. Static websites are a minority these days.

Fabio Coatti wrote:

mercoledì 23 aprile 2008, mike ha scritto:

  1. stop using spawn-fcgi. it sucks. use php-fpm. that’s not the fix to
    your issue, but it is something i recommend. :slight_smile:

It would be useful if you elaborate why is sucks. Otherwise your
argument
falls short. I’ve tried to browse a bit for some documentation, but it’s
only
in russian.

I upgraded to nginx-0.6.29, and tried Mike’s configuration, but I still
get a blank page when going to the home page of the site. Strangely
however, I can view pages in the Wordpress 2.5 control panel, however,
when I go to manage for articles and click next to view more, I get a
blank page again.

I’m obviously missing something small, but I don’t see what it is.

mike wrote:

In my experience:

It ignores the PHP_FCGI_MAX_REQUESTS completely
It didn’t kill the children properly

Running php-fpm is the best, it’s “done right”

2nd best - just set the two PHP_FCGI* vars and use “sudo -u $user
php-cgi -b $port” - it actually recycles the engines properly. I see
absolutely NO need for some extra thing. I set up my php engines in
Ubuntu upstart files. You could use init too, if you wanted. To ensure
it’s running at boot… or do something else.

You’d have to do the same with spawn-fcgi anyway.,

with spawn-fcgi you need to set a ALLOWED_ENV variable with all the
variables you want to pass to php-cgi. I have never had issues with
spawn-fcgi. Gentoo comes with a nice init script anyways for it.

Todd HG wrote:

short_open_tag = On

Because nothing else is jumping out at me I thought I’d entertain your
suggestion, so I switched to the default theme that comes with Wordpress
2.5, and ran into exactly the same issue as before. I’ve checked every
tag, and they are all correct. I know because I wrote every line of my
own theme, and the default wordpress theme appears to be correct as
well.

In my opinion, if Nginx doesn’t have a tutorial clearly explaining how
to configure and use Nginx with Wordpress, which is the number one blog
script software in the world, then Nginx isn’t ready for prime time.
Nginx won’t be widely accepted and used until it’s Wordpress friendly
with a proper tutorial, and support. I would love to write it and post
it on my tech site, but I can’t seem to even solve my own issue, and no
one appears to be able to help.

Nginx either works with Wordpress or it doesn’t. That’s not very
friendly, or practical. Static websites are a minority these days.
It is not Nginx’s responsibility to create guides for different
frameworks / applications its the Frameworks / applications that should
provide the guide to run it on X server. Nginx is a Web Server that
supports FastCGI, Reverse proxy’ing.

But to test, it took ~ 25 mins to get a full Wordpress blog up and
running (first time ever) on my nginx installation. I just followed
http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install
and then used this to setup search friendly URL’s.
http://thread.gmane.org/gmane.comp.web.nginx.english/637

On 4/24/08, Rob S. [email protected] wrote:

Never mind what i just said. ALLOWED_ENV is what is used on Gentoo how
they do there init scripts. Sorry for wrong information.

Trust me I fed different environment variables and then dumped the
information the processes were receiving, and spawn-fcgi’ed php
processes didn’t seem to have them.

To do PHP under FastCGI the best way, use PHP-FPM.

a) it improves some FastCGI shortcomings and improves performance in
certain situations
b) it allows for graceful process reloading
c) [soon] will fulfill the need for Suexec-capable adaptive process
spawning capabilities. It does the “suexec”-ish already. Soon it will
support Apache style process management.

It is everything one could hope for re: FastCGI process management
(PHP specific)

It helps mature PHP’s FastCGI implementation.

Andrei (the author) actually is the one who finally got me to think
about trying nginx too - because I thought “if this guy can get PHP
management right, he must know how to get the web right too” :slight_smile:

Rob S. wrote:

mike wrote:

In my experience:

It ignores the PHP_FCGI_MAX_REQUESTS completely
It didn’t kill the children properly

Running php-fpm is the best, it’s “done right”

2nd best - just set the two PHP_FCGI* vars and use “sudo -u $user
php-cgi -b $port” - it actually recycles the engines properly. I see
absolutely NO need for some extra thing. I set up my php engines in
Ubuntu upstart files. You could use init too, if you wanted. To ensure
it’s running at boot… or do something else.

You’d have to do the same with spawn-fcgi anyway.,

with spawn-fcgi you need to set a ALLOWED_ENV variable with all the
variables you want to pass to php-cgi. I have never had issues with
spawn-fcgi. Gentoo comes with a nice init script anyways for it.

Never mind what i just said. ALLOWED_ENV is what is used on Gentoo how
they do there init scripts. Sorry for wrong information.

Rob S. wrote:

Todd HG wrote:

short_open_tag = On

Because nothing else is jumping out at me I thought I’d entertain your
suggestion, so I switched to the default theme that comes with Wordpress
2.5, and ran into exactly the same issue as before. I’ve checked every
tag, and they are all correct. I know because I wrote every line of my
own theme, and the default wordpress theme appears to be correct as
well.

In my opinion, if Nginx doesn’t have a tutorial clearly explaining how
to configure and use Nginx with Wordpress, which is the number one blog
script software in the world, then Nginx isn’t ready for prime time.
Nginx won’t be widely accepted and used until it’s Wordpress friendly
with a proper tutorial, and support. I would love to write it and post
it on my tech site, but I can’t seem to even solve my own issue, and no
one appears to be able to help.

Nginx either works with Wordpress or it doesn’t. That’s not very
friendly, or practical. Static websites are a minority these days.
It is not Nginx’s responsibility to create guides for different
frameworks / applications its the Frameworks / applications that should
provide the guide to run it on X server. Nginx is a Web Server that
supports FastCGI, Reverse proxy’ing.

But to test, it took ~ 25 mins to get a full Wordpress blog up and
running (first time ever) on my nginx installation. I just followed
http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install
and then used this to setup search friendly URL’s.
http://thread.gmane.org/gmane.comp.web.nginx.english/637

Hi Rob,

Since you were able to successfully get Nginx to run Wordpress, would
you mind posting your config file?

I’ve been running Wordpress under Apache for several years, it’s just
running it under Nginx I’m having trouble with. Perhaps if I see a lot
of different config files I’ll eventually solve my own problem. I’d
really like to use Nginx, since I have a very high volume site that
requires two servers.

oh well i guess you are right here. That’s why wordpress.com - the
number 1 blog software is using nginx, just because it isn’t ready for
prime time. nginx is a web server. mind that when you make statements
that nginx should make guides for wordpress. wordpress works just fine,
you have to read the guides though.

I posted mine.

user www-data www-data;

worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;

working_directory /var/run;

error_log /var/log/nginx/error.log debug;

pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stre
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 100m; # More if you need up upload files
larger than 50mb
client_header_buffer_size 8k;
large_client_header_buffers 12 6k;
keepalive_timeout 5;

server_tokens off;
server_names_hash_max_size 4096;
server_names_hash_bucket_size 128;
server {
   listen 80;
   server_name michaelshadle.com www.michaelshadle.com;
   index index.php index.html;
   root /home/mike/web/michaelshadle.com/;
   location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
      expires 30d;
   }
   location ~ .php$ {
       include /etc/nginx/fastcgi.conf;
       fastcgi_pass 127.0.0.1:11000;
       fastcgi_index index.php;
   }
   if (!-e $request_filename) {
      rewrite ^(.+)$ /wordpress/index.php?q=$1 last;
   }

}
}

and my /etc/nginx/fastcgi.conf:

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

my wordpress is physically hosted inside of /wordpress/

otherwise, everything else is handled by either normal handling or the
!-e check, which passes it through wordpress.

piece of cake :slight_smile:

configure for PHP

‘./configure’ ‘–enable-fastcgi’ ‘–enable-discard-path’
‘–enable-force-cgi-redirect’ ‘–enable-fpm’
‘–with-fpm-pid=/var/run/php-fpm.pid’
‘–with-fpm-log=/var/log/php-fpm.log’
‘–with-fpm-conf=/etc/php-fpm.conf’ ‘–enable-cli’
‘–enable-inline-optimization’ ‘–disable-rpath’ ‘–disable-ipv6’
‘–enable-mbstring’ ‘–enable-mbregex’ ‘–enable-sqlite-utf8’
‘–with-mysql’ ‘–with-mysqli=/usr/bin/mysql_config’ ‘–with-curl’
‘–with-zlib’ ‘–with-gd’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’
‘–with-freetype-dir’ ‘–enable-gd-native-ttf’ ‘–enable-exif’
‘–enable-shmop’ ‘–with-xsl=shared’ ‘–with-mssql=shared’
‘–enable-soap=shared’ ‘–enable-sockets’ ‘–enable-pcntl=shared’
‘–with-mcrypt’ ‘–with-bz2’ ‘–with-tidy’ ‘–with-pcre-dir’
‘–with-imap=shared’ ‘–with-imap-ssl’ ‘–with-kerberos’ ‘–with-pear’

Just that Andrei does not have much to do with Nginx per say :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs