WordPress和nginx,下载一些页面,而不是提供服务

时间:2014-03-26 作者:tschiela

今天我用nginx安装了wordpress。问题是,我搞不清楚,有些页面将按预期提供,而另一些页面将作为下载。如果我下载它们,内容就是sama as索引。wordpress根文件夹中的php。我试图找出“正常”页面和其他缺陷页面之间的一些差异,但找不到任何人。

有趣的是,如果我给有问题的页面另一个永久链接(例如…/funktionen->../features),页面将被正确服务。如果切换回旧的永久链接,页面将被作为下载。

这是我的nginx配置:

#redirect
#  http://www.termin2go.com and
#  http://termin2go.com
# to
# https://www.termin2go.com
server {
        listen 80;
        server_name termin2go.com www.termin2go.com;
        rewrite ^(.*) https://www.termin2go.com$1 permanent;
}


# redirect
#   https://termin2go.com
# to
#   https://www.termin2go.com
server {
        listen 443 ssl;
        server_name termin2go.com;
        rewrite ^(.*) https://www.termin2go.com$1 permanent;
}

server {
        listen 443 ssl;
        server_name www.termin2go.com;
        ssl_certificate /etc/ssl/private/www.termin2go.com.crt;
        ssl_certificate_key /etc/ssl/private/www.termin2go.com.key;

        access_log  /var/log/nginx/termin2go.com.log;
        error_log /var/log/nginx/termin2go.com_error.log;
        set $root_path \'/var/www/wordpress\';
        root $root_path;
        charset utf-8;
        client_max_body_size 7M;

        # DEFAULT INDEX
        index index.php;

         # configure prerender for snapshot generation
        location / {
                try_files $uri $uri/ /index.php?$args @prerender;
        }
        location ~ /(\\.|wp-config.php|liesmich.html|readme.html) {
                return 444;
        }

        # REWRITES
        location ~ ^/(\\d+)/$ {
                return 301 /?p=$1;
        }

        # fix whitespace in url bug
        if ($request_uri ~ " ") { return 444; }

        # redirect google bot to prerender for ajax content (AngularJS)
        location @prerender {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                #proxy_intercept_errors on;

                set $prerender 0;
                if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\\.google\\.com") {
                        set $prerender 1;
                }

                if ($args ~ "_escaped_fragment_|prerender=1") {
                        set $prerender 1;
                }

                if ($http_user_agent ~ "Prerender") {
                        set $prerender 0;
                }

                if ($prerender = 1) {
                        rewrite .* /$scheme://$host$request_uri break;
                        proxy_pass http://127.0.0.1:4000;
                }

                if ($prerender = 0) {
                        rewrite .* /index.php break;
                }
        }

                # cache static files one month
        location ~* \\.(css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
                expires 31d;
                add_header Pragma "public";
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

 # cache static files 30 days
        location ~* \\.(css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
                expires 31d;
                add_header Pragma "public";
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \\.php$ {
                try_files $uri =404;

                fastcgi_split_path_info ^(.+\\.php)(/.+)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                include fastcgi_params;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_intercept_errors on;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

        # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
        location ~ /\\. {
                deny all;
                access_log off;
                log_not_found off;
        }
}

2 个回复
SO网友:Mike Rouse

在我的情况下,解决方案是:

清除Cloudflare中的缓存清除Google Chrome中的缓存

SO网友:imranhunzai

当我们的主机强制更新PHP版本时,我就遇到了这种情况。我们不得不替换一些过时的PHP函数。

结束

相关推荐

403 Forbidden error nginx

我从几天之后突然收到了这个错误(403禁止错误nginx)。我还没有修改网站上的任何内容,但这个错误不知从何而来。我可以在所有页面的顶部看到它。但是会显示页面。我正在使用Wordpress最新版本,托管在Powweb上。我已经询问了他们的支持团队,但他们对此一无所知,并要求我停用所有插件,然后进行检查。但在重命名插件目录和缓存目录之后,我也可以在我的网站上看到这个错误。我不明白突然出现的问题是什么?请帮帮我!UPDATE:通过对从www.jquerye请求jquery文件的代码进行注释,问题得以解决。co