drupalwxt / wxt

Drupal 10 variant of the Web Experience Toolkit (WxT).
https://drupalwxt.github.io
GNU General Public License v2.0
26 stars 27 forks source link

The resource from “http://.../en” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff). #204

Closed lawrenceong001 closed 4 years ago

lawrenceong001 commented 4 years ago

I ran into an issue while using running the site configured with Drush SI (after using Composer to create the project).

environment: Win10, WSL1 Ubuntu 18.04 PHP7.2 Nginx 1.14 Nodejs 12.16

after the site was enabled, I was able to load http://site, which switched to http://site/en, but the page returned was unstyled, and no graphic elements were displayed. upon closer inspection, it appears that I was getting console errors, with the message above.

there were subsequent errors (i.e. ReferenceError: jQuery is not defined), but it may be a symptom of the fact that the resources were prevented from being loaded.

it seems to be functioning though, since /user/login allowed me into the administration modules.

I tried composer on both 3.0.6 as well as 8.x-dev, and somehow both sites exhibited the same message.

would appreciate any help to resolve it.

tks.

sylus commented 4 years ago

Unfortunately this would indicate that something is wrong with your setup. As there is a myriad of different ways you could have setup your environment this isn't something we can really help with.

I'd double check your nginx settings and maybe compare against our dockerfiles to see if you notice something. The Drupal documentation might also provide some help.

https://github.com/drupalwxt/docker-scaffold/blob/master/Dockerfile https://github.com/drupalwxt/docker-scaffold/blob/master/conf/nginx.conf

lawrenceong001 commented 4 years ago

tks @sylus for your suggestion. I will post my nginx.conf tonight when i get back into the environment.

zachomedia commented 4 years ago

@lawrenceong001 Another thing you can do to check is to look at the Developer Tools network tab (in your browser) and see what content is being sent instead of the css and js. It's possible you're getting a 404 page not found instead.

That will help greatly with debug and comparing against your nginx config.

Also, have you looked at Drupal documentation for setting up your web server? We also have the Docker setup that has everything configured that you can try with as well.

lawrenceong001 commented 4 years ago

hi @zachomedia , I used the dev tools to get the message posted above. are you able to post the link to where this documentation is? I thought my drupal config was ok, since I was able to launch a basic drupal site from it, but I could be wrong.

with regards to using docker, as I'm on windows, can I launch the containers? I did some work on a another project (i.e. hyperledger), which caused all sorts of issues when run in win10.

zachomedia commented 4 years ago

@lawrenceong001 The network tab of the Dev Tools will give you the actual page content that was sent for the assets as that will be most useful in debugging. For Chrome, see https://developers.google.com/web/tools/chrome-devtools/network/reference#response. If you were able to launch a basic Drupal site, then Drupal WxT should also work with the same config.

Yes, if you have Docker Desktop for Windows in Linux container mode, you should be able to use the Docker images.

If you still have some issues, we'd be happy to have a chat with you on Friday morning to get help you out.

lawrenceong001 commented 4 years ago

tks @zachomedia & @sylus thus far! I will look into this tonight and let you guys know.

lawrenceong001 commented 4 years ago

Hi @zachomedia -- it doesn't look like i'm getting any 404s. here's my screenshot for your reference.

image

lawrenceong001 commented 4 years ago

hi @zachomedia , at the moment, my nginx.conf looks a bit different from your suggested .conf from docker-scaffold (it was pretty much the default if I'm not mistaken):

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}
lawrenceong001 commented 4 years ago

and to be sure I did the right thing:

  1. ran composer: php composer.phar create-project drupalwxt/wxt-project:8.x-dev wxt3 --no-interaction

  2. ran drush: drush si wxt --sites-subdir=default --db-url=mysql://<dbuser>:<dbpass>@<dbserver>:3306/wxt3 --account-name=<accountname> --account-pass=<accountpass> --site-mail=admin@example.com --site-name="Drupal Install Profile (WxT)" install_configure_form.update_status_module='array(FALSE,FALSE)' --yes

Composer: Composer version 1.9.3 2020-02-04 12:58:49 Drush: Drush version : 9.7.2

zachomedia commented 4 years ago

@lawrenceong001 Ok, I think I have a better understanding at the error now.

Can you check something in the webpage response you have? Can you find the <link rel="stylesheet" tags and <script tags and see what the URL for them are. They don't seem to contain the path to the actual resource and are instead pointing to the site root.

I think I had seen this in another site before when the sites/default/files folder wasn't writeable by the web server.

lawrenceong001 commented 4 years ago

hi @zachomedia, good question -- now i'm looking at what I did, and it appears I copied the entire drupalwxt folder over

here's what have on wxt3: image

and my site config is:

server {
    server_name _;
    root /var/www/wxt3/html; ## <-- Your only path reference.

    listen 8787;
    listen [::]:8787;
    # listen 443 default ssl;

    #ssl_certificate /etc/nginx/ssl/drupal.crt;
    #ssl_certificate_key /etc/nginx/ssl/drupal.key;

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

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

    # Very rarely should these ever be accessed outside of your lan
    #location ~* \.(txt|log)$ {
    # allow 192.168.0.0/16;
    # deny all;
    #}

    #location ~ \..*/.*\.php$ {
    # return 403;
    #}

    #location ~ ^/sites/.*/private/ {
    # return 403;
    #}

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
    return 403;
    }

    location / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # In Drupal 8, we must also match new paths where the '.php' appears in the middle,
    # such as update.php/selection. The rule we use is strict, and only allows this pattern
    # with the update.php front controller. This allows legacy path aliases in the form of
    # blog/index.php/legacy-path to continue to route to Drupal nodes. If you do not have
    # any paths like that, then you might prefer to use a laxer rule, such as:
    # location ~ \.php(/|$) {
    # The laxer rule will continue to work if Drupal uses this new URL pattern with front
    # controllers other than update.php in a future release.
    location ~ '\.php$|^/update.php' {
    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_buffering off;
fastcgi_read_timeout 300;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drpal >= 7
        try_files $uri @rewrite;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

that was the only way I could get this page to load, as copying the html folder didn't work.

please let me know if there should be another way.

with regards to privilege, I did a chmod a+w for the wxt3 folder...

finally, here's the html source -- it does appear that the link tags are pointing to root: image

tks Lawrence

zachomedia commented 4 years ago

Can you run the following drush command? drush ws

It should show any Drupal errors. I don't normally run this on Windows, but usually when we see the error you're encountering is caused by the sites/default/files either being read-only or not writeable by the user that php is running as.

lawrenceong001 commented 4 years ago

hi again @zachomedia,

here's the output of drush ws

 ----- -------------- ------ ---------- --------------------------------------------------------------------------
  ID    Date           Type   Severity   Message
 ----- -------------- ------ ---------- --------------------------------------------------------------------------
  610   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  609   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  608   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  607   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  606   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  605   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  604   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  603   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  602   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
  601   20/Feb 12:53   php    Warning    User warning: mkdir(): Permission Denied in
                                         Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 145 of
                                         /var/www/wxt3/html/core/lib/Drupal/Component/PhpStorage/FileStorage.php)
 ----- -------------- ------ ---------- --------------------------------------------------------------------------

which folders do I need to give acess to?

tks Lawrence

zachomedia commented 4 years ago

@lawrenceong001 You need to give access to sites/default/files

lawrenceong001 commented 4 years ago

hi @zachomedia, looks like I gave this folder all the privileges already, still getting the issue though: image

lawrenceong001 commented 4 years ago

hi @zachomedia when I run drush ws, there were no more new warnings about permission denied, so I'm assuming that's solved, but the page still looks like the screenshot I attached in my previous messages

zachomedia commented 4 years ago

@lawrenceong001 Can you run a drush cr to rebuild the caches? If it still doesn't look right, can you check the logs again with drush ws

lawrenceong001 commented 4 years ago

hi @zachomedia, tks for your help -- I'm now able to connect: image

it looks like the cache rebuild solved the issue!