D
D
Denis2014-03-12 17:27:45
PHP
Denis, 2014-03-12 17:27:45

Nginx + php-fpm, why are scripts being downloaded and not executed?

Hello! Busy migrating wordpress from nginx+apache to nginx + php-fpm. After setting it up, follow this manual: help.ubuntu.ru/wiki/nginx-phpfpm
When you click on a link that should be processed by a script, a file is downloaded with the following content:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

nginx config:
server
{
        listen 80;
        server_name site.ru;
        root    /var/www/site/wordpress;
        index                   index.php index.html index.htm;

location "/"    {
        index index.php index.html index.htm;
        try_files       $uri $uri/      =404;
        if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php break;
        }
}
location ~* "/\.ht"     {
        deny all;       # запретить все для всех
        return 404;     # вернуть код ошибки 404
}
location ~* "^/wordpress/(wp-config.php)((/.*)?)$"      {
        deny all;       # запретить все для всех
        return 404;     # вернуть код ошибки
}
location ~ \.php$ {

        location ~* "/(upload(s?)|image(s?)|attachment(s?))/"   {
                return 404;
        }
        fastcgi_pass    unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
        fastcgi_param   PATH_TRANSLATED         $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO               $fastcgi_path_info;
        fastcgi_param   SERVER_ADMIN            [email protected];      # почта администратора
        fastcgi_param   SERVER_SIGNATURE        nginx/$nginx_version;   # подпись сервера
        fastcgi_index   index.php;                                      # файл индекса

}
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2014-03-13
@uscr

Eka you have a curly config.
I'm not much of a WordPress expert - isn't there a single entry point?
To begin with, I would remove everything from FCGI_PARAM to include (so as not to clog the config).
This location

location "/"    {
        index index.php index.html index.htm;
        try_files       $uri $uri/      =404;
        if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php break;
        }
}

about nothing at all. It looks for the requested file, for example, and returns it if it finds it. It is he who gives the text of php files. And perishing condition - at all not understandable why.
In general, all manuals on Angie's configs should be found on Angie's website. And it's best to ask questions about Angie in the mailing list (not in the forum, it's just a frontend to the mailing list) - there are a lot of smart people there.

S
Stepan, 2014-03-12
@L3n1n

I don't see your location for php files. And in general for statics ..
First, configure nginx + php-fpm habrahabr.ru/post/113101
And then make additions under wordpress

S
Swasher, 2014-09-22
@Swasher

Exactly the same problem. Just info.php works, I can go to the admin panel - everything works in it, but the site itself does not. When accessing it, the file is loaded as in the first post of the TC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question