nginx & wordpress/php

Hello –

I'm having a problem getting nginx & php to work on one particular domain. The thing is, I managed to get it working with a different domain -- files were retrieved from the correct directory, and php files were being executed on the server. I've got nginx serving files for the second domain name from the correct place, but the php files are being sent as plain text and not executed. The relevant config files are below, and thanks for your help -- I'm a bit of a noob at this.

  • geoff


user www-data;
worker_processes  4;

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

events {
    worker_connections  1024;

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

    access_log    /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  10;
    tcp_nodelay        on;

    server_names_hash_bucket_size 64;  #added by gfg 04/18/2009

    gzip  on;

    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types  text/plain text/html text/css application/x-javascript text/xml
                application/xml application/xml+rss text/javascript;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


server {
        listen 80;
    rewrite ^/(.*)$1 permanent;

server {

    listen   80;
        access_log /home/username/dir1/dir2/log/access.log;
        error_log /home/username/dir1/dir2/log/error.log;

    location ~ /\. {
            deny  all;

    location ~  .*\.php$ {
        root /home/username/dir1/dir2/public/;
        fastcgi_index  index.php;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    location ~ / {
        root /home/username/dir1/dir2/public/;
        if ($document_uri ~ .+\.*jpg|jpeg|gif|css|js|png) {
            expires 30d;
        index index.php;



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  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;

0 Replies


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct