首页 > 系统相关 >Nginx 常用的基础配置(web前端相关方面)

Nginx 常用的基础配置(web前端相关方面)

时间:2023-06-30 09:02:35浏览次数:49  
标签:web index 前端 server Nginx html location gzip root

基础配置

user                            root;
worker_processes                1;

events {
  worker_connections            10240;
}

http {
  log_format                    '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"';
  include                       mime.types;
  default_type                  application/octet-stream;
  sendfile                      on;
  #autoindex                    on;
  #autoindex_exact_size         off;
  autoindex_localtime           on;
  keepalive_timeout             65;
  gzip                          on;
  gzip_disable                  "msie6";
  gzip_min_length               100;
  gzip_buffers                  4 16k;
  gzip_comp_level               1;
  gzip_types                  text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  gzip_types                    "*";
  gzip_vary                     off;
  server_tokens                 off;  #隐藏 Nginx 版本信息
  client_max_body_size          200m;
  
  
  server {
    listen                      80 default_server;  # 项目启动端口
    # listen                      80 default;  # 禁止ip直接访问80端口
    server_name                 _;    # 域名(localhost)
    return                      403 /www/403/index.html;
    add_header        X-Frame-Options SAMEORIGIN; # 禁止 iframe 嵌套

    # 访问地址 根路径配置
    location / {
      # 项目目录
      root 	    html;
      # 默认读取文件
      index           index.html;
      # 配置 history 模式的刷新空白
      try_files       $uri $uri/ /index.html;
    }
  
    # 后缀匹配,解决静态资源找不到问题
    location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ { 
      root           html/static/;
    }
  
    # 图片防盗链
    location ~/static/.*\.(jpg|jpeg|png|gif|webp)$ {
      root              html;
      valid_referers    *.deeruby.com;
      if ($invalid_referer) {
        return          403;
      }
    }
  
    # 访问限制
    location /static {
      root               html;
      # allow 允许
      allow              39.xxx.xxx.xxx;
      # deny  拒绝
      deny               all;
    }
  }

  include                       ../serve/*.conf;
}

参考地址传送

标签:web,index,前端,server,Nginx,html,location,gzip,root
From: https://www.cnblogs.com/tlf01/p/17515678.html

相关文章

  • 全栈测试开发系列----WebDriver API及对象识别技术(二)---selenium验证码处理的多种实现
    前言对于测试人员而言,不管是进行性能测试还是自动化测试,验证码的处理都是棘手的存在,在WEB应用中,大部分系统在用户登录的时候都要求用户输入验证码,且验证码的种类繁多,如纯数字、纯字母、汉子组合、数学题运算、滑动图标、图片、短信、邮箱、语音等。既然要实现验证码的处......
  • MongoDB从入门到实战之.NET Core使用MongoDB开发ToDoList系统(8)-Ant Design Blazor前端
    前言前面的章节我们介绍了一些值得推荐的BlazorUI组件库,通过该篇文章的组件库介绍最终我选用AntDesignBlazor这个UI框架作为ToDoList系统的前端框架。因为在之前的工作中有使用过AntDesignVue、AntDesignAngular习惯并且喜欢AntDesign设计规范和风格,废话不多说今天我......
  • 使用 Python WebSSH 从浏览器连接到SSH终端
    IntroductionOrdinarily,youconnecttoanSSHserverusingacommandlineappinaterminal,orterminalemulatorsoftwarethatincludesanSSHclient.Sometools,likePython’sWebSSH,makeitpossibletoconnectoverSSHandrunaterminaldirectlyin......
  • 内网使用postman测试websocket接口(无法登录的情况下)
    postman测试websocket接口。但是发现老版本的postman不支持websocket接口的测试。于是直接上最新版本postman。打开postman,new,选择websocket。发现选不了,提示:youneedtobeinaworkspacetoperformthisaction.然后我去工作台,发现强制要登录!!!但是问题在于:我这公司电脑不......
  • 注册功能 ,前端登录注册页面
    目录1异步发送短信1.1视图类1.2序列化类加入万能验证码2注册功能3.1视图类3.2序列化类补充3前端注册页面分析3.1Header.vue3.2Login.vue4前端登录注册页面复制4.1Login.vue4.2Register.vue4.3Header.vue5前端登录功能6前端注册功能1异步发送短信#原来的发送短......
  • Kubernetes 对象以及部署nginx服务示例(四)
    什么是Kubernetes对象?在k8s中管理员与平台交互的最重要方式之一就是创建和管理Kubernetes对象,对象有助于帮助用户部署应用程序和维护集群。理解Kubernetes对象的另一种方法是将它们视为类实例。每个创建的对象都引用一个预定义的类,该类告诉apiserver如何处理系统资源并......
  • 代理服务器之 squid、lvs、nginx、haproxy之间的区别
    代理服务器之squid、lvs、nginx、haproxy之间的区别代理服务可简单的分为正向代理和反向代理1、正向代理正向代理服务器:squid用于代理内部网络对Internet的连接请求(如VPN/NAT),客户端指定代理服务器,并将本来要直接发送给目标Web服务器的HTTP请求先发送到代理服务器上......
  • c#轻量级高并发物联网服务器接收程序源码(仅仅是接收硬件数据程序,没有web端
    c#轻量级高并发物联网服务器接收程序源码(仅仅是接收硬件数据程序,没有web端,不是java,协议自己写,如果问及这些问题统统不回复。),对接几万个设备没问题,数据库采用ef6+sqlite,可改ef+MySQL.该程序只是源码使用示例,里面有使用方法,自己研究,难度属中上层不建议新手拿原创文章,转载请说明出处......
  • 解决minio使用nginx代理出现问题(上传文件可以,创建桶404)
    minio使用nginx代理出现问题(上传文件可以,创建桶失败)server{listen80;#error_page500502503504404/404.html;注释掉location/{proxy_set_headerX-Forwarded-Proto$scheme;proxy_set_headerX-Real-IP$remote_addr;......
  • Nginx配置解决跨域问题
       server{      listen8080;      server_namelocalhost;       location/{         root/test;         indexindex.htmlindex.htm;          set$allow_cors0;         #判断不为空      ......