nginx代理配置
nginx代理配置
1、linux安装nginx默认目录
自动安装的nginx再linux下默认路径在
/etc/nginx
启动路径在/usr/sbin/
2、默认配置文件是
/etc/nginx/nginx.conf
1 # For more information on configuration, see: 2 # * Official English Documentation: http://nginx.org/en/docs/ 3 # * Official Russian Documentation: http://nginx.org/ru/docs/ 4 5 user nginx; 6 worker_processes auto; 7 error_log /var/log/nginx/error.log; 8 pid /run/nginx.pid; 9 10 # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. 11 # 可以加载指定路径下的配置文件加载到系统 12 include /usr/share/nginx/modules/*.conf; 13 14 events { 15 worker_connections 1024; 16 } 17 18 http { 19 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 20 '$status $body_bytes_sent "$http_referer" ' 21 '"$http_user_agent" "$http_x_forwarded_for"'; 22 23 access_log /var/log/nginx/access.log main; 24 25 sendfile on; 26 tcp_nopush on; 27 tcp_nodelay on; 28 keepalive_timeout 65; 29 types_hash_max_size 4096; 30 31 include /etc/nginx/mime.types; 32 default_type application/octet-stream; 33 34 # Load modular configuration files from the /etc/nginx/conf.d directory. 35 # See http://nginx.org/en/docs/ngx_core_module.html#include 36 # for more information. 37 include /etc/nginx/conf.d/*.conf; 38 39 server { 40 listen 80; 41 listen [::]:80; 42 server_name _; 43 root /usr/share/nginx/html; 44 45 # Load configuration files for the default server block. 46 include /etc/nginx/default.d/*.conf; 47 48 error_page 404 /404.html; 49 location = /404.html { 50 } 51 52 error_page 500 502 503 504 /50x.html; 53 location = /50x.html { 54 } 55 } 56 57 # Settings for a TLS enabled server. 58 # 59 # server { 60 # listen 443 ssl http2; 61 # listen [::]:443 ssl http2; 62 # server_name _; 63 # root /usr/share/nginx/html; 64 # 65 # ssl_certificate "/etc/pki/nginx/server.crt"; 66 # ssl_certificate_key "/etc/pki/nginx/private/server.key"; 67 # ssl_session_cache shared:SSL:1m; 68 # ssl_session_timeout 10m; 69 # ssl_ciphers HIGH:!aNULL:!MD5; 70 # ssl_prefer_server_ciphers on; 71 # 72 # # Load configuration files for the default server block. 73 # include /etc/nginx/default.d/*.conf; 74 # 75 # error_page 404 /404.html; 76 # location = /40x.html { 77 # } 78 # 79 # error_page 500 502 503 504 /50x.html; 80 # location = /50x.html { 81 # } 82 # } 83 84 }
3、include /etc/nginx/conf.d/*.conf;
可以对配置文件进行分类的工作,内容如下
1 server { 2 listen 8088;# 访问端口 3 server_name localhost; 4 #charset koi8-r; 5 #access_log /var/log/nginx/host.access.log main; 6 7 location /dss/visualis { 8 root /data/project/web; # 静态文件目录 9 autoindex on; 10 } 11 12 location /dss/linkis { 13 root /data/project/web; # 管理台的静态文件目录 14 autoindex on; 15 } 16 17 location / { 18 root /data/project/web/dist; # 静态文件目录 19 index index.html index.html; 20 } 21 22 location /datacenter { 23 root /data/project/dataCenter; # 管理台的静态文件目录 24 index index.html index.html; 25 } 26 27 28 29 30 location /ws { 31 proxy_pass http://localhost:9001;#后端的地址 32 proxy_http_version 1.1; 33 proxy_set_header Upgrade $http_upgrade; 34 proxy_set_header Connection upgrade; 35 } 36 37 38 location /warehouseHttp { 39 proxy_pass http://localhost:9088/dss/shucang; #后端地址 40 proxy_set_header Host $host; 41 proxy_set_header X-Real-IP $remote_addr; 42 proxy_set_header x_real_ipP $remote_addr; 43 proxy_set_header remote_addr $remote_addr; 44 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 45 proxy_http_version 1.1; 46 proxy_connect_timeout 4s; 47 proxy_read_timeout 600s; 48 proxy_send_timeout 12s; 49 proxy_set_header Upgrade $http_upgrade; 50 proxy_set_header Connection upgrade; 51 } 52 53 location /api { 54 proxy_pass http://localhost:9001; #后端的地址 55 proxy_set_header Host $host; 56 proxy_set_header X-Real-IP $remote_addr; 57 proxy_set_header x_real_ipP $remote_addr; 58 proxy_set_header remote_addr $remote_addr; 59 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 60 proxy_http_version 1.1; 61 proxy_connect_timeout 4s; 62 proxy_read_timeout 600s; 63 proxy_send_timeout 12s; 64 proxy_set_header Upgrade $http_upgrade; 65 proxy_set_header Connection upgrade; 66 } 67 68 #error_page 404 /404.html; 69 # redirect server error pages to the static page /50x.html 70 # 71 error_page 500 502 503 504 /50x.html; 72 location = /50x.html { 73 root /usr/share/nginx/html; 74 } 75 } 76
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!