php - Nginx Wordpress 无法访问博客文章但可以访问主页

标签 php wordpress ubuntu nginx

Nginx 版本:nginx/1.10.0 (Ubuntu 16.04)

这是我的博客conf:

server {
    listen 80;
    server_name blog.khophi.co;

    root /var/www/html/blog;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }

    location ~ /\.ht {
        deny all;
    }
}

按照步骤hereherehere

我可以访问网站主页,但文章页面,如 myblog.example.com/this-is-my-article不起作用。

最佳答案

这可能会有所帮助,

只需检查每一行并删除您认为不需要的行,

它是我一直用于每个 wordpress 设置的配置

server {
    listen       80;
    server_name  www.xxxxyour-domainxxxxx.com xxxxyour-domainxxxxx.com;
    return       301 https://xxxxyour-domainxxxxx.com$request_uri;
}

server {
    #listen 80;
    listen       443 default_server ssl spdy;
    server_name  xxxxyour-domainxxxxx.com;

    ssl on;
    ssl_certificate      /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.crt;
    ssl_certificate_key  /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.key;

    ssl_session_cache    shared:SSL:20m;
    ssl_session_timeout  10m;

    ssl_prefer_server_ciphers  on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;
    ssl_stapling on;
    ssl_stapling_verify on;

    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 10s;

    client_max_body_size 64m;
    client_body_timeout 60;

    #access_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com.log;
    error_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com-error error;

    root /var/www/xxxxyour-domainxxxxx.com;
    index  index.html index.php;


    location / {
        gzip_static on;

        error_page 418 = @cachemiss;

        if ($request_method = POST) { return  418; }

        if ($query_string != "") { return 418; }

        if ($http_cookie ~* "wordpress_logged_in_") { return 418; }
        if ($http_cookie ~* "comment_author_") { return 418; }
        if ($http_cookie ~* "wp_postpass_") { return 418; }

        try_files "/wp-content/cache/all${uri}index.html" =418;

        add_header "X-WPFC-Cache" "HIT";

        # choose or modify any of the following cache-control headers
        expires 30m;
        # add_header "Cache-Control" "max-age=10, must-revalidate";
        # add_header "Vary" "Cookie";
    }

    location @cachemiss {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    ### SECURITY ###
    error_page 403 =404;
    location ~ /\. { access_log off; log_not_found off; deny all; }
    location ~ ~$ { access_log off; log_not_found off; deny all; }
    location ~* wp-admin/includes { deny all; }
    location ~* wp-includes/theme-compat/ { deny all; }
    location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
    location /wp-includes/ { internal; }
    #location ~* wp-config.php { deny all; }
    location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
        types { }
        default_type text/plain;
    }

    ### DISABLE LOGGING ###
    location = /robots.txt { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }

    ### CACHES ###
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
    location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
    location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; }

    ### php block ###
    location ~ \.php?$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_hide_header X-Powered-By;
        #fastcgi_pass 127.0.0.1:9001;
        fastcgi_pass unix:/xxxx/dir/php-fpm/php-fpm.sock;

        #fastcgi_pass fpm;
        add_header "X-WPFC-Cache" "MISS";
    }
}

关于php - Nginx Wordpress 无法访问博客文章但可以访问主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151086/

相关文章:

php - SQL:计算每条记录的列值

mysql - 同一数据库中是否可以有不同的字符集?

php - 结帐时从 Woocommerce 产品属性中删除单词

mysql - 如何在本地将 Airflow 连接到 SQLite?

linux - Xargs 不听标准输入

javascript - 如何引用动态创建的变量

javascript - 该脚本不会重新加载已加载的 php

Ruby - Watir webdriver 在 browser.goto(url) 后超时,即使 URL 已成功加载

php - 我们如何烘焙 cakephp 上的查找字段?

mysql - WordPress 添加自定义列