之前帮公司的商会做官网,涉及到了旧官网的图片等资源迁移到新官网上,用Nginx做路由处理,正好今天发了Nginx的相关内容,把这篇小纪也发了出来
server {listen 3335;server_name xx.xx.xx.xxx;location /{root /www/server/sxhnsh/manager;index index.html index.htm;}location /imageRepository {alias /www/server/sxhnsh/imageRepository;}}
大概配置如下,这里也记录一下root与alias的区别:
root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上。
例如:
location /test/ {root /www/server/hello}
如果一个请求的url是/test/hello.html的话,那么web服务器将会返回服务器上的/www/server/hello/test/hello.html文件,也就是:path/url
location /test/ {alias /www/server/hello}
如果一个请求的url是/test/hello.html的话,那么web服务器将会返回服务器上的/www/server/hello/hello.html文件
- 使用alias时,目录名后面一定要加”/“。
 - alias可以指定任何名称。
 - alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。
 - alias只能位于location块中。
 
一般情况下,在location /中配置root,在location /other中配置alias。
