?1.配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
#gzip on;
upstream service_test {
server 127.0.0.1:8088;
}
server {
listen 9080;
server_name localhost;
# 静态资源文件
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|doc|docx|mp4)$
{
root html;
autoindex on;
}
# 非静态资源文件
location ~ .*$ {
proxy_pass http://service_test;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
常用命令
# 启动 ?start nginx.exe # 停止 nginx.exe -s stop
# 查看log日志 端口冲突,
使用命令打开netstat -ano | findstr 80找到80端口有哪些程序在占用,发现了很多个 可以通过tasklist | findstr ?pid 查看进程相关信息,如,下面这个是我又打开了多个ngnix后,和上面端口对不上
#结束进程 taskkill /f /t /im nginx.exe
# 配置负载均衡后,通过nginx代理后getRequestURL无法获取正确域名,设置请求域
? https://www.jianshu.com/p/0514c3454c8c
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
|