Welcome! Log In Create A New Profile

Advanced

Odd 500 Internal Server Error with a Wordpress file

Posted by endikos 
Odd 500 Internal Server Error with a Wordpress file
August 04, 2012 12:08AM
Hey folks. I'd appreciate some help with this bit of wierdness: Fresh install of wordpress downloaded earlier today, running on nginx with a fastcgi_pass to php-fpm. The install went flawlessly, and most everything seems to work correctly, except that when I click on the "Posts" button in the admin interface (/wp-admin/edit.php), I get a mostly blank screen that says "Invalid Post Type". Like I said, this is a completely fresh install, so I don't have ANY custom page types or anything, it's perfectly default right now. While I've performed plenty of wordpress installs without issue, I'm a relative neophyte to nginx anf php-fpm, and am sure something's gone wrong somehow on the backend. I do notice that php-fpm is logging a 500 status code when I hit that page, but can't seem to get any meaninful error message in the browser telling me exactly what went wrong. Nginx is connecting to php-fpm via fastcgi_pass to a unix domain socket. Any ideas from those more experienced than me?

Thanks!!
Bill
Re: Odd 500 Internal Server Error with a Wordpress file
August 04, 2012 01:15PM
I'd check the php error log for more information.

In my setup I have the php.ini for php-fpm setup to send errors to syslog, which in turn routes them to a specific file that I check.

You can also configure php to log directly to a file, provided that the file has the correct permissions set (usually owned by the user that you run php-fpm as, 640).

I'd check that file and the php-fpm log (in my case it is /var/log/php5-fpm.log).

It's kind of a side-note, but nginx's location blocks usually give me a lot of grief as I'm still nailing down just what order I can expect them to be processed in. With some other web apps I made the mistake of setting the content expiration date too aggressive and was getting 404 errors when the content was available.

It may be that you have your location blocks misconfigured. Posting more information would probably help to pinpoint the problem.

It could also be a problem with the unix socket you've specified. I think I ran into a problem when I was changing my setup from a localhost tcp socket to a unix socket, and if I remember right it was a permissions issue.

Still, here is the default location block I use for https connections:

# pass the PHP scripts to FastCGI server listening on a UNIX socket
location ~ \.php$ {
# http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid#sph_important-security-considerations
#try_files $uri =404;
# I'm already doing that in the vhost configs that use PHP, so I'm electing to not duplicate the setup
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.default.sock;
}

If you're not using a SSL connection then just remove the 'fastcgi_param HTTPS on;' line.
Re: Odd 500 Internal Server Error with a Wordpress file
September 29, 2012 05:29PM
Hi. Just wondering if you found a solution to this problem? I'm having a similar issue and have not found any working solutions yet, even after spending the entire day on it. Would be very appreciative for any info/pointers you might have. Thx,
Re: Odd 500 Internal Server Error with a Wordpress file
September 29, 2012 07:24PM
Yeah, it came down to a pathing issue. IIRC, it was the fastcgi_param lines, in DOCUMENT_ROOT, SCRIPT_FILENAME, and PATH_TRANSLATED... essentially, nginx was passing incorrect paths to php-fpm, and this was causing the 500 errors, even though the logs weren't being very verbose about it. Hope that helps!
Re: Odd 500 Internal Server Error with a Wordpress file
September 30, 2012 03:54AM
Thanks for the tip. Would it be possible for you to post your fastcgi_param lines? I've tried a bunch of settings there, but nothing seems to make any difference. Here's what I have for the php configuration. Note that I'm running wordpress off a subdirectory, which was painless with Apache, but nginx is non-trivial.

location /blog {
passenger_enabled off;
alias /path/to/wordpress;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
}

location ~ \.php$ {
include /opt/nginx/conf/fastcgi_params;
fastcgi_split_path_info ^/blog/(.+\.php)(.*)$;
fastcgi_param DOCUMENT_ROOT /path/to/wordpress;
fastcgi_param SCRIPT_FILENAME /path/to/wordpress/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED /path/to/wordpress/$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
Re: Odd 500 Internal Server Error with a Wordpress file
September 30, 2012 05:05PM
ok, I'm including my entire config for you here. There are a few things you should probably be aware of:

1) The main app served at '/' is a rails 3 app. I'm using rvm to manage gem sets and make sure the app is owned an run as a local user, not the nginx daemon user.
2) I'm using passenger standalone bound to a unix domain socket for raw speed on the rails app.
3) Wordpress is being served from a subdirectory, or rather what appears to the end-user to be a subdirectory, and am using php-fpm to serve up a fastcgi process.
4) I use capistrano for deployment, two separate deployments, actually... one for rails, one for the main wordpress files.
5) This thing runs wickedly fast. :-)

Hope this helps. Let me know how you end up.

#####################################
# Some Variables have been changed to protect the innocent ;-)
#####################################

#####################################
# First up, nginx.conf
#####################################

user <daemon_owner_user> <daemon_owner_group>;
worker_processes 10;

error_log logs/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

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

access_log logs/access.log combined;

sendfile on;
keepalive_timeout 65;

gzip on;
gzip_comp_level 9;
gzip_types text/plain text/xml text/css text/x-js application/x-javascript;
gzip_disable "MSIE [1-6]\.";

include sites-enabled/*.conf;
}

#####################################
# Next, www.mysite.tld.conf
#####################################

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

server {
listen <listening_ip_addy>:80;
server_name mysite.tld;
rewrite ^(.*) http://www.mysite.tld$1 permanent;
}

server {
listen <listening_ip_addy>:80;
server_name www.atbbq.com;

include sites-available/www.mysite.tld.common;
}

server {
listen <listening_ip_addy>:443;

ssl on;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL;
ssl_certificate_key /usr/local/nginx/ssl/www.mysite.tld.clearkey;
ssl_certificate /usr/local/nginx/ssl/www.mysite.tld.bundle.crt;

include sites-available/www.mysite.tld.common;
}

#####################################
# Then, www.mysite.tld.common
#####################################

location / {
proxy_redirect off;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/<app_user>/www.mysite.tld/root/passenger.sock:/;
}

# optimize exec regexp
location /blogsubdir/ {
root /home/<app_user>/www.mysite.tld/blogsubdir/current;
index index.php;
error_page 404 = @wp;
# PHP ($document_root = alias section)
location ~ ^/blogsubdir/.+\.php {
fastcgi_index index.php;
#fastcgi_intercept_errors on;
fastcgi_ignore_client_abort on;
fastcgi_read_timeout 180;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_pass unix:/var/sock/php-fpm.sock;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
include fastcgi_params;
}
# static
location ~* ^/blogsubdir/(.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv))$ {
# dynamic path
root /home/<app_user>/www.mysite.tld/blogsubdir/current;
}
}


location @wp {
rewrite ^/blogsubdir/(.+)$ /blogsubdir/index.php?q=$1 last;
}

# general static
location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
root /home/<app_user>/www.mysite.tld/root/current/public;
}

#####################################
# Finally, just in case you need it, here's the fastcgi_params
#####################################

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_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 HTTPS $https if_not_empty;

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;
Re: Odd 500 Internal Server Error with a Wordpress file
October 06, 2012 01:02PM
endikos, Thanks a lot for showing your config file. My setup is very similar to yours except that I run passenger as a nginx module (compiled in with passenger-install-nginx-module) and I'm not using capistrano for wordpress. Unfortunately I wasn't able to get your config to work at all in my setup. It never seemed to execute any of the php, saying things like "file not found", etc. I tried lots of different things, but eventually went back to running the blog in apache2 with mod_php and using nginx to proxy over to it. This works fine, but is probably not as optimized for speed as using php5-fpm would be. But it's still fast enough for my current needs.

For anyone else whose interested, here are the relevant sections of my nginx config and the virtual host file for apache2.

#####################
# Nginx - relevant parts only
#####################

upstream myblog {
# Apache with mod_php running on 8088
server 127.0.0.1:8088;
}
server {
listen 80;

server_name www.tld.com tls.com;

location / {
root /home/me/sites/tld.com/current/public;
passenger_enabled on;

passenger_use_global_queue on;
passenger_min_instances 1;
rails_framework_spawner_idle_time 0;
rails_app_spawner_idle_time 0;

access_log /home/me/sites/tld.com/logs/access.log;
error_log /home/me/sites/tld.com/logs/error.log notice;

# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
}

location /blog {
proxy_pass myblog;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;

proxy_max_temp_file_size 0;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}

##########################
# Apache2 - virtual server for /blog
##########################

<VirtualHost 127.0.0.1:8088>
ServerName blog.tld.com
ServerAlias blog.tld.com
ServerAdmin info@tld.com

ErrorLog /home/me/sites/tld.com/logs/blog-error.log
CustomLog /home/me/sites/tld.com/logs/blog-access.log combined

Alias /blog /home/me/sites/tld.com/wordpress

DocumentRoot /home/me/sites/tld.com/wordpress
DirectoryIndex index.php

<Directory /home/me/sites/tld.com/wordpress/>
Options FollowSymLinks
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 160
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready