0

Forgive me ahead of time for my lack of knowledge on this topic

When I send a basic auth request (via header) to my url https://www.mywebsite.com, the PHP server variables such as "PHP_AUTH_PW" and "HTTP_AUTHORIZATION" exist for me to validate and authorize.

However, if I visit my website url without the www, eg: https://mywebsite.com, the PHP server variables "PHP_AUTH_PW" and "HTTP_AUTHORIZATION" do not exist.

I should also mentioned that I am using cloudflare that sits in front of my nginx server. Cloudflare also provides my ssl and redirects my non https requests to https.

Note: /blog is not part of the website I am trying to access.

Any help to why I can't access the basic auth vars would be appreciated!

Also, all recommendations/suggestions are welcome on how my nginx is configured.

Below is my nginx config:

# Expires map
map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

#===============================
#   Listener Configuration
#===============================

server {
      listen 80;
        server_name mywebsite.com www.mywebsite.com;


#===============================
#   Basic Configuration
#===============================
        root /var/www/html;
        index index.php index.html index.htm;

    #===========================
    #   Logs Configuration
    #===========================

        access_log /var/log/nginx/mywebsite-access.log;
        error_log  /var/log/nginx/mywebsite-error.log;

    #========================
    #   Location default
    #========================

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

        }

    #========================
        #   Location proxy
        #========================
    location ~ ^/blog(.*)$ {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://0.0.0.0;
    proxy_redirect default;
        client_max_body_size    20m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   120s;
        proxy_send_timeout      120s;
        proxy_read_timeout      120s;
        proxy_buffering         off;
        proxy_temp_file_write_size 128k;
        proxy_redirect          off;
        proxy_set_header Authorization "Basic ##############";

}



    #=============================
    #   PHP-FPM Configuration
    #=============================

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_param PATH_INFO $fastcgi_path_info;
            # With php-cgi alone:
            #fastcgi_pass 127.0.0.1:8008;

        fastcgi_send_timeout 6000;
        fastcgi_read_timeout 6000;
            # With php-fpm:
            fastcgi_pass unix:/run/php/php5.6-fpm.sock;


            fastcgi_index index.php;
            fastcgi_intercept_errors on;
            include fastcgi.conf;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
        }


    location ~ [^/]\.php(/|$) {

    add_header X-Fastcgi-Cache $upstream_cache_status; # Add header so we can see if the cache hits or misses

    # the rest of your existing stuff to handle PHP files here
    }


    #===================================
    #   Static Content Configuration
    #===================================

        location ~* \.(ico|jpg|webp|jpeg|gif|css|png|js|ico|bmp|zip|woff)$ {
            expires 365d;
                add_header Pragma public;
            add_header Cache-Control "public";
        }

        #Laverage cache expires
    location ~* \.(?:ico|gif|jpe?g|jpg|jpeg|png|svg)$ {
            access_log        off;
            log_not_found     off;
            expires 30d;
            add_header Pragma public;
            add_header Cache-Control "public, max-age=3000";
            fastcgi_hide_header Set-Cookie;
            add_header Vary "Accept-Encoding";
            gzip_vary on;
        gzip_proxied any;
        gzip_http_version 1.0;
    }

    location ~* \.(?:css|js)$ {
            access_log        off;
            log_not_found     off;
            add_header Pragma public;
            add_header Cache-Control "public, max-age=300";
            fastcgi_hide_header Set-Cookie;
            add_header Vary "Accept-Encoding";
            gzip_vary on;
    }

    if ($host = mywebsite.com) {
        return 301 https://www.mywebsite.com$request_uri;
    } 



}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.