使用Nginx为静态资源提供服务
1. 打开nginx 的 config 文件
可以使用 include 命令导入配置
2. 编写 beyond.conf 文件
server {
listen 89;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 90;
server_name localhost;
location / {
root /home/foodie-shop;
index index.html; # 非以/为路径的location, 不写 index, index 是在foodie-shop 下的文件
}
# 访问连接例如: 192.168.181.134:90/beyond/img/face.png img在/home/beyond的目录下
location /beyond{
# 从/后的beyond路径进行路由访问 (实际路径是 /home/beyond/img)
root /home; # 静态资源路径
}
# 访问连接例如: 192.168.181.134:90/static/img/face.png
location /static {
# 从/后的static 这个别名进行路由访问 (它的实际路径下面配置的 /home/beyond/img)
# alias 用来定义别名static的实际路径
alias /home/beyond;
}
}