Nginx set static resources based on path

Source: Internet
Author: User
nginx access to server static resources based on specific paths
A recent requirement is that the URL specify a path to access the server's static resources. The simple configuration always reports 404 errors. Description is that Nginx cannot find the resources you have configured. There are two kinds of static resource allocation methods common to nginx agent. One is to specify the file type.
Location ~/(javascript|css|images) {
        root/users/web;
    }
The other is to specify the file path, which we set.
Location ^~/ma/{
        root/users/web;
    }
~ starts with a case-sensitive regular match, ^ non, = the beginning represents an exact match, and not all of this is explained here.

Our configuration is as follows: Place our resource files under/var/deploy/fpos_mobile/fpos/. The goal is to access the server static resources directly when we access the http://shop.fpsit.trendy-global.com/MA/. However, it has not been accessible.


It was not until we saw the alias that the root path configuration problem occurred.
Location ^~/ma/{
        alias/users/web;
    }
When I have the same browser access/ma/index.html use root to map to/users/web/ma/index.html
Using alias maps directly to/user/web/index.html This is why resources are not found. So, depending on our resource location, you can access it by simply changing the root to alias.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.