首页 > 系统相关 >nginx简单配置

nginx简单配置

时间:2023-02-01 14:00:38浏览次数:43  
标签:http log 配置 server nginx conf 简单 upstream

nginx代理静态网页

vim /etc/nginx/nginx.conf

# nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$time_local | $host | $status | $request_length | $bytes_sent | $upstream_addr | $upstream_response_time | '
                      '$http_referer | $remote_addr | $remote_user | $request | $request_uri | '
                      '$http_user_agent | $http_x_forwarded_for | $cookie_Mac';

    log_format  api_main  escape=json '$time_local | $host | $status | $request_length | $bytes_sent | $upstream_addr | $upstream_response_time | '
                      '$http_referer | $remote_addr | $remote_user | $request | '
                      '$http_user_agent | $http_x_forwarded_for | $cookie_Mac | $http_authorization | $request_body';

    access_log  /var/log/nginx/access.log  main;
    client_max_body_size     1024m;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   35;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

vim /etc/nginx/conf.d/eval.conf

#eval.conf
server {
    listen 3020;
    server_name 192.168.110.21;
    access_log /var/log/nginx/eval.log api_main;
    root /home/hyc/eval/html/dist/;
    location / {
        try_files $uri /index.html;
    }
}

nginx负载均衡

#user  nobody;
worker_processes  1;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    #在server上添加此upstream节点
    upstream mytomcat{
    #分权 即访问131与134的次数比例为1比1
        server localhost:5001 weight=1;  #springboot1 内置tomcat运行的端口
        server localhost:5002 weight=1;  #springboot2 内置tomcat运行的端口
        server localhost:5003 weight=1;  #springboot3 内置tomcat运行的端口
        }
        
    # HTTPS server
    server {
        listen 5000 ;
        server_name localhost;
        #即所有请求都到这里去找分配
        location / {
       #使用mytomcat分配规则,即刚自定义添加的upstream节点
           proxy_pass http://mytomcat;
        }
    }
}

标签:http,log,配置,server,nginx,conf,简单,upstream
From: https://www.cnblogs.com/hyhc8848/p/17082326.html

相关文章

  • 简单分析USB设备驱动框架
    在生活、工作中经常会接触到USB设备,如鼠标、键盘、摄像头、可移动硬盘、扫码枪等。这些设备通过USB接口连接到电脑上后,电脑会立刻提示“检测到新硬件...”、安装驱动等。这......
  • IIS 配置 HTTPS
    1、导入证书a、开始->运行->MMC,打开MMC  b、文件->添加/删除管理单元c、双击证书,添加d、计算机用户      ......
  • tomcat简单配置
    1.网页拷贝到webapps目录2.编辑conf/server.xml<?xmlversion="1.0"encoding="UTF-8"?><Serverport="8005"shutdown="SHUTDOWN"><ListenerclassName="org.apach......
  • vscode 配置
    {"window.zoomLevel":2,"[go]":{"editor.insertSpaces":false,"editor.formatOnSave":true,"editor.codeActionsOnSave":{......
  • 简单分块与莫队
    1-分块1.1-定义分块是将要维护的信息分成若干块,而后通过维护整块的信息或者是块间的信息来优化算法。1.2-序列分块在序列上以线段树来类比,线段树是将序列每次对......
  • 从零开始配置vim(31)——git 配置
    很抱歉又拖更了这么久了,在这个新公司我想快速度过试用期,所以大部分的精力主要花在日常工作上面。但是这个系列还是得更新下去,平时只能抽有限的业余时间来准备。这就导致我......
  • android自定义adapter之简单写法
      自定义adapter比较常用,很多人还在使用extendsBaseAdapter,然后写一大堆重复的代码,这里是提供一个封装的工具类,把重复的代码都省略掉,让adapter变的简洁一些。  给......
  • jpa多数据源时Hibernate配置自动生成表不生效
    jpa配置多数据源教程很多,在Springboot2之后有一些变化,来看一下。application.yml如下:spring:application:name:t3ccdatasource:primary:jdbc-url:jdb......
  • ffmpeg 简单教程
    关于ffmpeg的另一个帖子​​​https://www.cnprint.org/bbs/thread/83/345103/​​检测是否安装成功环境变量:测试是否安装成功win+r输入:cmdcmd:输入ffmpeg-version......
  • python pyqt5简单界面
    ​​https://doc.qt.io/qtforpython/PySide6/QtWidgets/QTableWidget.html​​importsysfromPyQt5.QtWidgetsimportQApplication,QWidget,QDesktopWidget,QHBoxLayou......