Nginx服务器代理静态资源

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32483145/article/details/81254017

1.修改H:\nginx-1.8.1\conf\nginx.conf文件

添加一个server节点到nginx.conf文件中:访问itemimage文件夹下面的静态资源应该是#1+#2,如下访问资源12.png应该是image.yufan.com/12.png. 将#2改为/itemimage/,#3改为H:/IntelliJ IDEA 2018.1.2/Projects/yufan/admin/src/main/webapp后访问路径变为image.yufan.com/itemimage/12.png.

server {
        listen       80;
        server_name  image.yufan.com; #1
        #root目录中含有空格,可以使用双引号,root为静态资源根目录
        #没有空格则无需双引号
        location  /{    #2
            root   "H:/IntelliJ IDEA 2018.1.2/Projects/yufan/admin/src/main/webapp/itemimage"; #3
            autoindex on;
        }

    }

2.修改C:\Windows\System32\drivers\etc\host文件:
添加下面语句到host文件中就可以按照上述访问路径访问静态资源了。

127.0.0.1   image.yufan.com

注意:如果你只需要访问localhost路径,那么将#1改为localhost,则无需配置host文件就可以使用localhost/12.png访问静态资源了。

猜你喜欢

转载自blog.csdn.net/qq_32483145/article/details/81254017