服务/ wc-api /通过http而不是https NGINX

时间:2017-03-19 18:42:04

标签: wordpress http nginx https http-status-code-404

我遇到问题,API需要使用http才能在我的网站上正常运行,并且我强制所有流量都使用HTTPS。 我做了一些修改但仍然无法使其正常工作。 在/ wc-api /上添加重定向之前,当我使用curl http:// site .com / wc-api / v3(需要使用http工作的url)时,我总是永久移动301;但是现在有了这些变化,我收到了404找不到的错误,所以缺少了一些东西。 非常感谢您的帮助。提前谢谢!

这是我的nginx配置:

    fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name site.com www.site.com;
    location / {
    return 301 https://$server_name$request_uri;
    }
    location /wc-api/ {
    }
    }
    server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-params.conf;

    client_max_body_size 256M;
    root /var/www/html;
    index index.php index.html;

    server_name site.com www.site.com;

    # this must be near the top to ensure auto-renewals work
    location ~ /.well-known {
            allow all;
    }

    set $skip_cache 0;

    if ($request_method = POST) {
            set $skip_cache 1;
    }

    if ($query_string != "") {
            set $skip_cache 1;
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
            set $skip_cache 1;
    }

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
            set $skip_cache 1;
    }

    autoindex off;

    location ~ /purge(/.*) {
            fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }
    location ~* ^.+\.(flv|pdf|avi|mov|mp3|wmv|m4v|webm|aac|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|ex$
            expires max;
            log_not_found off;
            access_log off;
    }

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

    location /wc-api/ {
            return 301 http://$server_name$request_uri;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;
            fastcgi_cache WORDPRESS;
            fastcgi_cache_valid 60m;
            include fastcgi_params;
    }
    location ~* ^/wp-includes/.*(?<!(js/tinymce/wp-tinymce))\.php$ {
            internal;
    }

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

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

    location = /wp-config.php {
            deny all;
    }

    location ~* /(?:uploads|files)/.*\.php$ {
            deny all;
    location ~* ^/wp-content/.*\.(txt|md|exe|sh|bak|inc|php|pot|po|mo|log|sql)$ {
            deny all;
    }

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

0 个答案:

没有答案