Статус 403 при вызове WordPress на nginx без префикса протокола

Когда я звоню в свой интернет-магазин в Chrome или любом другом веб-браузере без префикса https, я получаю статус 403. Я не знаю почему. Ошибка появляется, так как я установил и удалил плагин колибри от wpmudev.

Вот моя конфа:

Я использую WordPress с woocommerce на экземпляре Ubuntu 14.04 aws ec2. Дополнительно сайт защищен ssl. Плагин NGINX Helper присутствует и активен, но в этой ситуации его не трогали.

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;

   server_name example.com www.example.com 52.29.193.xxx;

        #root /home/wordpress/htdocs;
   root /var/www/letsencrypt;

   location ^~ /.well-known/acme-challenge/ {
      default_type "text/plain";
      root         /var/www/letsencrypt;
   }

        index index.html index.htm index.php index.cgi index.pl index.xhtml;

        #rewrite ^(.*) https://example.com$1 permanent;
}

server {
   listen *:443 ssl;

   ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
   ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;

   server_name example.com www.example.com 52.29.193.xxx;

   root /home/wordpress/htdocs;

   index index.html index.htm index.php index.cgi index.pl index.xhtml;

   #rewrite ^(.*) https://example.com$1;

   port_in_redirect off;

   set $skip_cache 0;

        error_log off;
        access_log off;

   # POST requests and urls with a query string should always go to PHP
   if ($request_method = POST) {
      set $skip_cache 1;
   }   
   if ($query_string != "") {
      set $skip_cache 1;
   }   

   # Don't cache uris containing the following segments
   if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
      set $skip_cache 1;
   }   

   if ($request_uri ~* "/home.*|/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
           set $skip_cache 1;
   }

   if ($request_uri ~* "/en/home.*|/en/store.*|/en/cart.*|/en/my-account.*|/en/checkout.*|/en/addons.*") {
                set $skip_cache 1;
        }

   if ( $arg_add-to-cart != "" ) { 
      set $skip_cache 1;
   }

   if ( $cookie_woocommerce_items_in_cart != "0" ) {  
      set $skip_cache 1;
   }

   # Don't use the cache for logged in users or recent commenters
   if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
      set $skip_cache 1;
   }

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

   # Directives to send expires headers and turn off 404 error logging.
   location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
      access_log off; 
      log_not_found off; 
      expires max;
   }

   # Pass all .php files onto a php-fpm/php-fcgi server.
   location ~ \.php$ {
      set $rt_session "";

      if ($http_cookie ~* "wc_session_cookie_[^=]*=([^%]+)%7C") {
                     set $rt_session wc_session_cookie_$1;
            }  
      if ($skip_cache = 0 ) {
         more_clear_headers "Set-Cookie*";
         set $rt_session "";
      }
           fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";

      try_files $uri =404;    
      include fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/wordpress.sock;
      fastcgi_index index.php;
      fastcgi_read_timeout 300;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_cache_bypass $skip_cache;
           fastcgi_no_cache $skip_cache;

      fastcgi_cache WORDPRESS;
      fastcgi_cache_valid  60m;
   }
   location ~ /purge(/.*) {
       fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
   }  
   location /user {
         rewrite ^ https://$host$request_uri? permanent;
        }
   location = /xmlrpc.php {
      deny all;
      access_log off;
      log_not_found off;
   }
   location ~ ^/wp-content/uploads/wsoe/(.*?)\.csv$ {
      rewrite / permanent;
   }
}

Если возможно, дайте какое-нибудь объяснение, чтобы я мог узнать что-то об этой проблеме.

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 127.0.0.1:8080;
   listen *:443 ssl;

   ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
   ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;

   server_name example.com www.example.com;

   root /home/wordpress/htdocs;

   index index.html index.htm index.php index.cgi index.pl index.xhtml;

   port_in_redirect off;

   set $skip_cache 0;

        error_log off;
        access_log off;

   # POST requests and urls with a query string should always go to PHP
   if ($request_method = POST) {
      set $skip_cache 1;
   }   
   if ($query_string != "") {
      set $skip_cache 1;
   }   

   # Don't cache uris containing the following segments
   if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
      set $skip_cache 1;
   }   

   if ($request_uri ~* "/home.*|/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
           set $skip_cache 1;
   }

   if ($request_uri ~* "/en/home.*|/en/store.*|/en/cart.*|/en/my-account.*|/en/checkout.*|/en/addons.*") {
                set $skip_cache 1;
        }

   if ( $arg_add-to-cart != "" ) { 
      set $skip_cache 1;
   }

   if ( $cookie_woocommerce_items_in_cart != "0" ) {  
      set $skip_cache 1;
   }

   # Don't use the cache for logged in users or recent commenters
   if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
      set $skip_cache 1;
   }

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

   # Directives to send expires headers and turn off 404 error logging.
   location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
      access_log off; 
      log_not_found off; 
      expires max;
   }

   # Pass all .php files onto a php-fpm/php-fcgi server.
   location ~ \.php$ {
      set $rt_session "";

      if ($http_cookie ~* "wc_session_cookie_[^=]*=([^%]+)%7C") {
                     set $rt_session wc_session_cookie_$1;
            }  

      if ($skip_cache = 0 ) {
         more_clear_headers "Set-Cookie*";
         set $rt_session "";
      }

           fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";

      try_files $uri =404;    


      include fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/wordpress.sock;
      fastcgi_index index.php;
      fastcgi_read_timeout 300;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      fastcgi_cache_bypass $skip_cache;
           fastcgi_no_cache $skip_cache;

      fastcgi_cache WORDPRESS;
      fastcgi_cache_valid  60m;
   }

   location ~ /purge(/.*) {
       fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
   }  

   #location = /xmlrpc.php {
   #  deny all;
   #  access_log off;
   #  log_not_found off;
   #}

}

person radscheit    schedule 27.08.2016    source источник
comment
вы хотите, чтобы ваш сайт работал с http или просто перенаправлял http на https?   -  person Dusan Bajic    schedule 27.08.2016
comment
только https. это интернет-магазин.   -  person radscheit    schedule 27.08.2016


Ответы (1)


Вы можете попробовать изменить часть http на:

server {
    listen *:80;
    server_name example.com www.example.com 52.29.193.xxx;

    location ^~ /.well-known/acme-challenge/ {
        default_type "text/plain";
        root         /var/www/letsencrypt;
    }

    location / {
        rewrite ^(.*) https://example.com$1 permanent;
    }
}
person Dusan Bajic    schedule 27.08.2016
comment
Спасибо, я попытался перезапустить nginx, но это не сработало. - person radscheit; 27.08.2016
comment
Вы по-прежнему получаете 403 при попытке открыть http://www.example.com/, а https://www.example.com/ работает нормально? - person Dusan Bajic; 27.08.2016
comment
Да, он работает с префиксом https, но не с префиксом http или без префикса. - person radscheit; 27.08.2016
comment
Возможно, есть еще один файл .conf с конфигурацией example.com? - person Dusan Bajic; 27.08.2016
comment
Да, добавил в пост выше. Но в этом файле за 2 месяца ничего не изменилось, вместо первого выложенного мной файла, который изменился вчера. - person radscheit; 27.08.2016
comment
Перед этим экземпляром есть Elastic Load Balancer? - person Dusan Bajic; 27.08.2016