0

I have googled this problem and found lots of references, but none of the workarounds or solutions seem to work in my case. I have a docker container with an Nginx acting as an SSL reverse proxy for authentication. I have an Apache container serving a Laravel app. I always get the html but no css or images. In Chrome I get:

Resource interpreted as Stylesheet but transferred with MIME type text/html:

Here is my default.conf in nginx/sites/

upstream app {
       server 172.18.0.6;
}
server {

listen 443 ssl default_server;
listen [::]:443 ssl default_server ipv6only=on;
server_name rocket.example.com localhost;
root /var/www/public;
index index.php index.html index.htm;
include /etc/nginx/mime.types;
 # tell users to go to SSL version this time
     if ($ssl_protocol = "") {
     rewrite     ^   https://$server_name$request_uri? permanent;
     }

 add_header Strict-Transport-Security "max-age=15768000";
 ssl_certificate /etc/nginx/rocket.crt;
 ssl_certificate_key /etc/nginx/rocket.key;
 ssl_dhparam /etc/nginx/rocket_dhparam.pem;
 ssl_session_cache shared:SSL:10m;
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;
 ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK";
 error_page 497  https://$host:$server_port$request_uri;
 ssl_verify_client on;
 ssl_verify_depth 10;
 ssl_client_certificate /etc/nginx/allcerts.pem;


location / {
     try_files $uri $uri/ /index.php$is_args$args;
     include /etc/nginx/mime.types;
}

location ~ \.php$ {
        proxy_pass http://app;
        proxy_http_version 1.1;
        proxy_set_header Host $host:$server_port;
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header X-Client-Verify $ssl_client_verify;
        proxy_set_header X-Client-DN $ssl_client_s_dn;
        proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;

        proxy_send_timeout 86400;
        proxy_read_timeout 86400;
        include /etc/nginx/mime.types;


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

As I mentioned, none of the other solutions have worked. Can anyone see a mistake that could be causing this? I have put the proxy_ directives in both locations, with the same effect. Any help would be extremely appreciated.

1
0

The location containing proxy_pass is set to only proxy PHP files. This line here

location ~ \.php$ {   

The first thing I'd try is moving that whole block into the main "location /" block.

Your https rewrite uses an if statement, which isn't ideal - read "if is evil". If you want clients to use https the best way is to create a series of servers to forward, like this

# Forward non-www requests to www
server {
  listen       80;
  server_name  example.com www.example.com;
  access_log  /var/log/nginx/hr.access.log main buffer=128k flush=1m if=$log_ua;
  return       301 https://www.example.com$request_uri;
}

server {
  listen 443 ssl http2;
  server_name example.com;

  ssl_certificate /var/lib/acme/certs/***CERT_DIRECTORY/fullchain;
  ssl_certificate_key /var/lib/acme/certs//***CERT_DIRECTORY/privkey;

  # Set up preferred protocols and ciphers. TLS1.2 is required for HTTP/2
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

  access_log  /var/log/nginx/hr.access.log main buffer=128k flush=1m if=$log_ua;

  return 301 https://www.example.com$request_uri;
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.