192.168.137.2
node1:/etc/nginx#cat /etc/nginx/nginx.conf
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
worker_connections 1024;
}
# http conf
http {
#include http/common.conf;
#include http/cache.conf;
#include http/resty.conf;
#include http/mime.types;
include http/*.conf;
include http/servers/*.conf;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_filename"';
access_log logs/access.log main;
upstream backend1 {
server 192.168.137.3:8090 weight=5;
}
#charset koi8-r;
#access_log logs/host.access.log main;
server{
listen 8090;
server_name localhost;
ssl on;
#从腾讯云获取到的第一个文件的全路径
ssl_certificate /etc/ssl/server.pem;
ssl_certificate_key /etc/ssl/server.key;
location ^~ /backoffice
{
proxy_pass https://backend1/backoffice;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
打印出的日志:
192.168.137.1 - - [29/Apr/2020:17:29:09 +0800] "GET /backoffice/ HTTP/1.1" 200 215 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/usr/local/nginx/html/backoffice/"
192.168.137.1 - - [29/Apr/2020:17:29:09 +0800] "GET /backoffice/index.css HTTP/1.1" 304 0 "https://192.168.137.2:8090/backoffice/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/usr/local/nginx/html/backoffice/index.css"
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
worker_connections 1024;
}
# http conf
http {
#include http/common.conf;
#include http/cache.conf;
#include http/resty.conf;
#include http/mime.types;
include http/*.conf;
include http/servers/*.conf;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_filename"';
access_log logs/access.log main;
#charset koi8-r;
#access_log logs/host.access.log main;
server{
listen 8090;
server_name localhost;
ssl on;
#从腾讯云获取到的第一个文件的全路径
ssl_certificate /etc/ssl/server.pem;
ssl_certificate_key /etc/ssl/server.key;
location / {
root /var/www/demo/html;
index index.html;
}
location /backoffice {
root /var/www/html;
index index.html index.htm;
if ($request_filename ~ .*.(js|css|htm|html)$)
{
expires -1;
}
}
}
}
192.168.137.2 - - [09/Apr/2020:08:21:24 +0800] "GET /backoffice/ HTTP/1.0" 200 215 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "192.168.137.1" "/var/www/html/backoffice/index.html"
192.168.137.2 - - [09/Apr/2020:08:21:24 +0800] "GET /backoffice/index.css HTTP/1.0" 304 0 "https://192.168.137.2:8090/backoffice/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "192.168.137.1" "/var/www/html/backoffice/index.css"
nginx 日志出现
192.168.137.2:
node1:/root#cat /etc/nginx/nginx.conf
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
worker_connections 1024;
}
# http conf
http {
#include http/common.conf;
#include http/cache.conf;
#include http/resty.conf;
#include http/mime.types;
include http/*.conf;
include http/servers/*.conf;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_filename"';
access_log logs/access.log main;
upstream backend1 {
server 192.168.137.3:8090 weight=5;
}
#charset koi8-r;
#access_log logs/host.access.log main;
server{
listen 8090;
server_name localhost;
ssl on;
#从腾讯云获取到的第一个文件的全路径
ssl_certificate /etc/ssl/server.pem;
ssl_certificate_key /etc/ssl/server.key;
location ^~ /backoffice
{
proxy_pass https://backend1/backoffice;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
192.168.137.3:
node2:/root#cat /etc/nginx/nginx.conf
# Copyright (C) 2019 by chrono
# you can run openresty on linux
# sudo /usr/local/openresty/bin/openresty -p ..
# sudo /usr/local/openresty/bin/openresty -p .. -s stop
# sudo /usr/local/openresty/bin/openresty -p .. -s reload
# wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
# ./configure --with-openssl=$HOME/Downloads/openssl-1.1.1b --with-openssl-opt='enable-tls1_3' --with-http_v2_module
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
worker_connections 1024;
}
# http conf
http {
#include http/common.conf;
#include http/cache.conf;
#include http/resty.conf;
#include http/mime.types;
include http/*.conf;
include http/servers/*.conf;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_filename"';
access_log logs/access.log main;
#charset koi8-r;
#access_log logs/host.access.log main;
server{
listen 8090;
server_name localhost;
# ssl on;
#从腾讯云获取到的第一个文件的全路径
# ssl_certificate /etc/ssl/server.pem;
# ssl_certificate_key /etc/ssl/server.key;
location / {
root /var/www/demo/html;
index index.html;
}
location /backoffice {
root /var/www/html;
index index.html index.htm;
if ($request_filename ~ .*.(js|css|htm|html)$)
{
expires -1;
}
}
}
}
请求:https://192.168.137.2:8090/backoffice
192.168.137.1 - - [30/Apr/2020:14:52:10 +0800] "GET /backoffice HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/usr/local/nginx/html/backoffice"
192.168.137.2 - - [09/Apr/2020:14:21:12 +0800] "x16x03x01x00xF2x01x00x00xEEx03x03^xAAux9A.WC&xEEx97|4I" 400 157 "-" "-" "-" "/usr/local/nginx/html"