nginx反向代理:兩個域名指向不同web服務端口


一台服務器上安裝了zabbix服務和jumpserver服務,兩個域名zabbix.xxxx.xxxx和jumserver.xxx.xxxx

一、編輯/etc/nginx/conf.d目錄下nginx.conf

添加

include /etc/nginx/conf.d/*.conf;

二、在/etc/nginx/conf.d目錄下新建zabbix.conf文件

server {
    listen       80;                               //監聽80
    server_name  zabbix.xxxx.com;   //設置訪問的域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
      root   /var/www/zabbix;     //zabbix web的根目錄
      index  index.php index.html index.htm;
    } 

    

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/zabbix;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/zabbix$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

三、在/etc/nginx/conf.d目錄下新建jumpserver.conf文件

server {
    listen       80;   //監聽80
    server_name  jumpserver.xxxx.com;  //設置訪問的域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location /static/{
      root /usr/local/jumpserver/data/;
    }
    
    location /luna/ {
        try_files $uri / /index.html;
        alias /usr/local/luna/;  # luna 路徑, 如果修改安裝目錄, 此處需要修改
    }

    location /media/ {
        add_header Content-Encoding gzip;
        root /usr/local/jumpserver/data/;  # 錄像位置, 如果修改安裝目錄, 此處需要修改
    }

    location /socket.io/ {
        proxy_pass       http://localhost:5000/socket.io/;  # 如果coco安裝在別的服務器, 請填寫它的ip
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
    location /coco/ {
        proxy_pass       http://localhost:5000/coco/;  # 如果coco安裝在別的服務器, 請填寫它的ip
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
    location /guacamole/ {
        proxy_pass       http://localhost:8081/;  # 如果guacamole安裝在別的服務器, 請填寫它的ip
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
     
   location / {
        proxy_pass http://localhost:8080/;            //訪問域名指向這個ip的端口web服務(反向代理)
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    # location ~ \.php$ {
    #    root           /var/www/;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

四、重啟nginx服務

service nginx reload

五、驗證

瀏覽器打開:http://jumpserver.xxx.com

 

瀏覽器打開:http://zabbix.xxxx.com

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM