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