子目录中的nginx和wordpress导致访问被拒绝

时间:2017-12-16 21:37:48

标签: php wordpress nginx

我在同一个域上运行了两个rails应用程序和一个wordpress。 rails应用程序运行正常,但我无法让wordpress在子目录中运行。它起源于root。

我在nginx error.log中收到以下错误。请注意路径中的双重wordpress,这是问题,但我不知道如何解决它!真正的路径是/ var / www / wordpress而不是/ var / www / wordpress / wordpress!

2017/12/16 21:15:18 [error] 17341#17341: *7 FastCGI sent in stderr: "Access 
to the script '/var/www/wordpress/wordpress' has been denied (see 
security.limit_extensions)" while reading response header from upstream, 
client: ...

这是我的nginx配置:

server {
    server_name www.example.com;
    listen 443 ssl;
    root /var/www/first_rails_app/public;
    passenger_enabled on;
    passenger_app_root /var/www/first_rails_app/;
    passenger_document_root /var/www/first_rails_app/public;
    rails_env    production;

    index index.htm index.html;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location /wordpress {
        try_files $uri $uri/ /wordpress/index.php?$args;
        root /var/www/wordpress;
        index index.php;
        passenger_enabled off;

        location ~ .php(?|$) {
            try_files $uri =404;
            fastcgi_split_path_info ^(/wordpress)(/.*)$;
            fastcgi_pass unix:/run/php/php5.6-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            #passenger_enabled off;
        }                        
    }

    location ~ ^/second_rails_app(/.*|$) {
        alias /var/www/second_rails_app/public$1;  # <-- be sure to point to 'public'!
        passenger_base_uri /second_rails_app;
        passenger_app_root /var/www/second_rails_app/;
        passenger_document_root /var/www/second_rails_app/public;
        passenger_enabled on;
    }

    ssl_session_timeout  5m;

    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers   on;

    client_max_body_size 4G;
    keepalive_timeout 10;

}

1 个答案:

答案 0 :(得分:0)

问题出在这里

    try_files $uri $uri/ /wordpress/index.php?$args;
    root /var/www/wordpress;

您的try_files行说查找请求的文件,如果找不到,请检查它是否是目录,如果不起作用,则提供根目录+ /wordpress/index.php?$args,即{{1 }}

对于Wordpress,这应该可行

/var/www/wordpress/wordpress/index.php?$args