linux nginx配置反向代理
查找 find / -name nginx.conf
[root@test ~]# cd /etc/nginx/conf.d [root@test conf.d]# vi /usr/local/nginx/conf/nginx.conf [root@test conf.d]# vi nginx.conf [root@test conf.d]# find / -name nginx.conf /etc/nginx/nginx.conf [root@test conf.d]# vi /etc/nginx/nginx.conf [root@test conf.d]#
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; 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; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } "/etc/nginx/nginx.conf" 90L, 2469C
上面得到原始的 配置文件
修改文件后
server { listen 80; server_name www.xxx.com; #代理服务器本机的域名或者IP
#charset koi8-r; #access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://www.xxx.com;
}
:qw 回车
[root@test ~]# nginx -s reload [root@test ~]# vi /etc/nginx/nginx.conf [root@test ~]# vi /etc/nginx/nginx.conf [root@test ~]# nginx -s reload [root@test ~]#
重启 nginx
nginx -s reload
2.添加多个一个路由,注意:这里 buy必须是域名下对应的文件夹路径
location /buy { root html; index index.html index.htm; proxy_pass http://www.xxx.com; }
当访问 http://n2.xxxxx.cn/buy 则是第二个
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
2018-01-19 一台服务器的IIS绑定多个域名