UserFrosting Nginx asset-raw 404 【SOLVED】

I am using Nginx and I am not using Apache. So I need a piece of Nginx code to solve the loading problem of the front-end static resources.

My problem is similar to this, but I am not Apache. I didn’t find what I wanted in the ‘webserver-configs’ folder.

The following code does not seem to work.

location ~* \.(png|gif|jpg|jpeg|svg|ico|css|js|woff|ttf|otf|woff2|eot)$ {
  index index.php;
  try_files $uri $uri/member/public/asset-raw/ member/public/index.php?$query_string;
}

The following Nginx rule configuration code can correctly solve the above problem.
:heavy_check_mark: After my actual test.

  ## Begin - UserFrosting Caching static files
  location ~* \/member\/.*\.(png|gif|jpg|jpeg|svg|ico|css|js|woff|ttf|otf|woff2|eot|json)$ {
    index index.php;
    try_files $uri $uri/ /member/public/index.php?$query_string;
  }
  ## End - UserFrosting Caching static files

  ## Begin - Index
  ## for subfolders, simply adjust:
  ## `location /subfolder {`
  ## and the rewrite to use `/subfolder/index.php`
  location /member/public/ {
    index index.php;
    try_files $uri $uri/ /member/public/index.php?$query_string;
  }
  ## End - Index

Can you paste your whole nginx config file here so we can check it properly? (If it’s super long, put it in a gist or similar.)

Have you tried the full code for the static assets?

location ~* \.(png|gif|jpg|jpeg|svg|ico|css|js|woff|ttf|otf|woff2|eot)$ {
        include /etc/nginx/mime.types;
        expires max;

        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }

From what you posted it looks like you might be missing some vital bits to it. Give the above a try and remember to restart the nginx service after changes.

@josh.norris

This code will cause the website to be inaccessible. My ‘UserFrosting’ root directory is ‘member’ and the website root directory is the ‘member’ upper level folder.

Then you’ll need to adjust the code to account for the folder changes. The point was that there appears to be missing code for the static elements not showing up.

Any success @zhangchenglin?

To filter the blocks down to just that folder, you should only need to adjust the location block regex

location ~* \/member\/.*\.(png|gif|jpg|jpeg|svg|ico|css|js|woff|ttf|otf|woff2|eot)$ {
        include /etc/nginx/mime.types;
        expires max;

        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }

That should work, but it is untested in an actual environment. The regex will match correctly though and because you’ve filtered down the location block that it executes for, you shouldn’t need to adjusted the try_files

Let us know how it goes.

This code parses the static file into the index.php file in the root directory of the website. It does not resolve to member/public/index.php. Should it be resolved to member/public/index.php, so that it can be ‘Sprinkle’? To take over the next job?

  ## Begin - UserFrosting Caching static files
  location ~* \/member\/.*\.(png|gif|jpg|jpeg|svg|ico|css|js|woff|ttf|otf|woff2|eot|json)$ {
    index index.php;
    try_files $uri $uri/ /member/public/index.php?$query_string;
  }
  ## End - UserFrosting Caching static files

This code solves most of the static file 404 problems.
Does not include font-awsome font files.
Login page (/member/public/account/sign-in) is still in 404 status code

QQ%E6%88%AA%E5%9B%BE20190515180050

QQ%E6%88%AA%E5%9B%BE20190515181359

QQ%E6%88%AA%E5%9B%BE20190515182016

QQ%E6%88%AA%E5%9B%BE20190516102717

The font file loading failure is caused by the Nginx configuration sequence. After the order is adjusted, the font file can be loaded correctly.