• nginx 多域名指向多个根目录配置,设置自定义请求头 proxy_set_header,ssl 证书安装配置


    1.nginx.conf 配置文件引入子配置文件 include vhost-server/*.conf;  关键在 server_name  不同域名执行不同的根

    user  root;
            #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 {
            client_max_body_size 20m;
            include       mime.types;
            default_type  application/octet-stream;
    
            underscores_in_headers on;
            #add_header X-Frame-Options SAMEORIGIN;
            #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/dev_access.log;
    
            sendfile        on;
            #tcp_nopush     on;
    
            #keepalive_timeout  0;
            keepalive_timeout  65;
    
            #gzip  on;
    
    
    
           
              include vhost-server/*.conf; 
            }
    

      2. vhost-server 下子配置 a.conf    b.conf 

    a.conf

    server { 
        listen 80;
            listen 443 ssl;
            server_name  test.com;
            #ssl on;
            ssl_certificate      cert/test/test.pem;
            ssl_certificate_key  cert/test/test.key;
            ssl_session_timeout 5m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_prefer_server_ciphers on;
            error_log logs/sitxqy_error.log;
            access_log logs/sitxqy_access.log;
    
      autoindex on; # 显示目录
      autoindex_exact_size on; # 显示文件大小
      autoindex_localtime on; # 显示文件时间
    
               root html/test/;
               index index.html;
    
    client_max_body_size  20m;
       
    location /api/ {    
            proxy_pass http://localhost:88/;
            proxy_set_header   Host    $host;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
            
    #   location ~ .*.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|less|map|eot|svg|ttf|woff|woff2|cab|scss|otf|exe|pdf|doc|xlsx)$ { 
    #          root html/xqc-h5/cloudSign;
    #          index index.html;
    #       }
     
        location / {
               try_files $uri $uri/ /index.html;
        }
    
        location /a {
               try_files $uri $uri/ /a/index.html;
        }
    
    
           error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
               index index.html;
            }       
            }
    

      b.conf

    server { 
        listen 80;
            listen 443 ssl;
            server_name testa.com;
            #ssl on;
            ssl_certificate      cert/testa.pem;
            ssl_certificate_key  cert/testa.key;
            ssl_session_timeout 5m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_prefer_server_ciphers on;
            error_log logs/sitxqy_error.log;
            access_log logs/sitxqy_access.log;
    
        autoindex on; # 显示目录
        autoindex_exact_size on; # 显示文件大小
        autoindex_localtime on; # 显示文件时间
    
               root html/cloudSignOpen;
               index index.html;
    
        client_max_body_size  20m;
       
        location /api/ {    
            proxy_pass http://localhost:88/;
            proxy_set_header   Host    $host;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
            
        location / {
               try_files $uri $uri/ /index.html;
        }
    
        location /a {
               try_files $uri $uri/ /a/index.html;
        }
    
    
           error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
               index index.html;
            }       
            }
    

      

  • 相关阅读:
    vscode开发环境安装配置-连载【2】-企业级系统开发实战连载系列 -技术栈(vue、element-ui、qt、c++、sqlite)
    nodejs开发环境安装-连载【1】-企业级系统开发实战连载系列 -技术栈(vue、element-ui、qt、c++、sqlite)
    vs 2015 菜单重复的问题解决方法
    ecshop代码详解之init.php
    前端jquery实现点击图片弹出大图层(且滚动鼠标滑轮图片缩放)
    thinkPHP中省市级联下拉列表
    mysql函数date_format统计刷选按年月日统计的数据
    jQuery插件实现select下拉框左右选择_交换内容(multiselect2side)
    php代码生成二维码
    ASP.NET无效的视图
  • 原文地址:https://www.cnblogs.com/yun965861480/p/10606033.html
Copyright © 2020-2023  润新知