1

不久前,我设法在我的 VPS 上安装了 Virtualmin,目前正在运行 WordPress。我也在使用 Nginx。

从我所做的备份中恢复我的博客后,我能够启动并运行它并开始设置插件。

我最初使用 yoast,并尝试生成一个站点垫,但它没有用 - 我一直收到 404 错误。我什至使用 FTP 检查并没有找到文件。所以我在网上查找了解决方案并尝试了所有方法,刷新永久链接,添加 htaccess 规则,向 nginx.conf 添加重写规则,清除缓存等等。但没有任何效果。

我什至还尝试上传一个虚拟的 sitemap_index.xml 文件并刷新了站点地图设置,但它从未被读取或更新。

所以我决定也尝试其他插件,All-in-One SEO、Jetpack、Google 站点地图,但遗憾的是它们都无法创建站点地图。

这是我的 .htaccess 文件

# WordPress SEO - XML Sitemap Rewrite Fix
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
</IfModule>
# END WordPress SEO - XML Sitemap Rewrite Fix

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

这是我的 nginx 配置(ikigainetwork.moe.conf)

server {
    server_name ikigainetwork.moe www.ikigainetwork.moe;
    listen 81.4.104.56;
    root /home/ikigainetwork/public_html;
    index index.html index.htm index.php;
    access_log /var/log/virtualmin/ikigainetwork.moe_access_log;
    error_log /var/log/virtualmin/ikigainetwork.moe_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;
    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_FILENAME /home/ikigainetwork/public_html$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT /home/ikigainetwork/public_html;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    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;
    fastcgi_param HTTPS $https;
    location / {
                try_files $uri $uri/ /index.php?$args; 
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/php-nginx/14911244012458.sock/socket;
    }
location ~* \.(txt|xml|js)$ {
    expires 8d;
}

location ~* \.(css)$ {
    expires 8d;
}

location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$ {
    expires 8d;
}

location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
    expires 8d;
}
    listen 81.4.104.56:443 default ssl;
    ssl_certificate /home/ikigainetwork/ssl.cert;
    ssl_certificate_key /home/ikigainetwork/ssl.key;

#Yoast sitemap
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
    rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
        rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

        ## following lines are options. Needed for wordpress-seo addons
        rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
    rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
    rewrite ^/geo_sitemap\.xml$ /index.php?sitemap=wpseo_local last;
    rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;

    access_log off;
}

}
4

1 回答 1

0

我有一个 使用插件的wordpress安装。 我也遇到了站点地图提供的问题。 这是为我解决的问题:
XML Sitemap Generator for WordPress 4.1.0
404

location / {
    try_files $uri $uri/ /index.php?$args;

    location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
        }
}

将站点地图重写放在里面location ~解决了我的问题。

于 2019-07-13T11:55:41.473 回答