当前位置:首页 > 服务器技术 > nginx

nginx_proxy多虚拟主机解决方案

  • 背景

技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/10/20221110042357892.jpg" title="lb.png" />

  • 要求

  1. 不考虑session会话保持

  2. 通过域名来访问不同的虚拟主机。

  • nginx_proxy配置

[root@mysql conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
upstream backend {
    server 192.168.1.198:80       max_fails=3 fail_timeout=30s;
    server 192.168.1.197:80       max_fails=3 fail_timeout=30s;
}
    server {
        listen       80;
        server_name  www.chborg.com;
        location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  bbs.chborg.com;
        location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  blog.chborg.com;
        location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
  •  web服务配置

[root@lnmpconf]# cat nginx.conf
worker_processes  1;
error_log  logs/error.log error;
events{
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    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;
    include extra/www.conf;
    include extra/bbs.conf;
    include extra/blog.conf;
}

注解:此处省略extra内的server标签配置

本文出自 “挨刀客” 博客,请务必保留此出处http://chboy.blog.51cto.com/9959876/1705346

原文:http://chboy.blog.51cto.com/9959876/1705346


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!