JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

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

wys521 2024-10-03 03:55:13 精选教程 30 ℃ 0 评论

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直接代理,避免浪费服务器资源,然而也可以作为前置机。

详见:nginx 代理转发 http https 基本用法文章。


人人为我,我为人人,欢迎您的浏览,我们一起加油吧。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表