首页 服务器技术 nginx

nginx托管静态网站及静态资源基本用法

nginx作为一个具有高性能httphttps反向代理web服务器,非常适合托管静态资源文件。

它的优点太多,在这里就不一一解说,我们直接看实际应用例子。


1、网站在nginx目录

1.1 默认

目录

网页代码

server{
   # 监听的端口
   listen      14553;
   # 绑定的域名,多个用空格分开即可。
   server_name localhost prvt.cool www.prvt.cool;
   location / {
       root web;
       index index2.html;
   }
}


1.2 别名/虚拟目录

目录

网站目录

server{
   # 监听的端口
   listen      14553;
   # 绑定的域名,多个用空格分开即可。
   server_name localhost prvt.cool www.prvt.cool;
   location / {
       root web;
       index index2.html;
   }
   location /new2 {
       alias web/new;
       index indexNew.html;
   }
}


2、网站在其它目录

目录

默认

别名/虚拟目录

server{
   # 监听的端口
   listen      14553;
   # 绑定的域名,多个用空格分开即可。
   server_name localhost prvt.cool www.prvt.cool;
   location / {
       alias E:/demo/web/;
       index index2.html;
   }
   location /new2 {
       alias E:/demo/web/new/;
       index indexNew.html;
   }
}


3、代理其它web服务器(静态)站点

这种完全可以通过NGINX直接代理,避免浪费服务器资源,然而也可以作为前置机。

相关推荐