阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

如何给Nginx绑定多个端口

194次阅读
没有评论

共计 3057 个字符,预计需要花费 8 分钟才能阅读完成。

实例介绍在 Nginx 上绑定了 80 端口,网站打开正常。现在想要再加一个 8080 和 8089 端口的绑定,应该怎么做?

有两种方法:

一、在 server 段写上 2 个 Listen 就可以了.

listen 192.168.0.123:8080;
listen 192.168.0.123:8089;
如上, 就可以同时监听 2 个端口了.

二、在 nginx.conf 中配置多个个 server 即可

user nginx nginx;

worker_processes  1;

worker_rlimit_nofile 65535;

events {worker_connections  4000;
}

http {include       mime.types;
    default_type  application/octet-stream;
    autoindex off;

    log_format  main  '$remote_addr - $remote_user [$time_local]"$request" '
                      '$status $body_bytes_sent"$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                       '$upstream_addr $upstream_response_time $request_time';
    access_log  logs/nginx/access.log main;

    sendfile        on;

    keepalive_timeout  65;

        upstream localhost {server 127.0.0.1:80800 max_fails=7 fail_timeout=7s;
    } 

    server {listen       8080;
        server_name  localhost;
                large_client_header_buffers 4 128k;
        client_max_body_size 300m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers   4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;

# 设定查看 Nginx 状态的地址
        location /nginxstatus{stub_status on;
            access_log on;
            auth_basic "nginxstatus";
            auth_basic_user_file htpasswd;
    }

#ftpweb
         location /ftpweb {index  index.html index.htm index.jsp;
           proxy_pass  http://192.168.0.16:9081/ftpweb;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header Host $host:$server_port;
        }

#Zabbixweb
         location /webzabbix/ {index  index.html index.htm index.jsp;
           proxy_pass  http://192.168.0.123/zabbix/;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header Host $host:$server_port;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {root   html;
        }

    }

    server {listen       8089;
        server_name  localhost;
        large_client_header_buffers 4 128k;
        client_max_body_size 300m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers   4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;

# 开放 8089 接口地址
         location /interserver {index  index.html index.htm index.jsp;
           proxy_pass  http://192.168.0.20:8812/interserver/;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header Host $host:$server_port;
        }

    }

}

这样就就可以一个 nginx 服务访问 8080 和 8089 两个端口到不同服务的了
http://192.168.0.123:8080/ftpweb
http://192.168.0.123:8089/interserver

下面关于 Nginx 的文章您也可能喜欢,不妨参考下:

Nginx 403 forbidden 的解决办法  http://www.linuxidc.com/Linux/2017-08/146084.htm

CentOS 7 下 Nginx 服务器的安装配置  http://www.linuxidc.com/Linux/2017-04/142986.htm

CentOS 上安装 Nginx 服务器实现虚拟主机和域名重定向  http://www.linuxidc.com/Linux/2017-04/142642.htm

CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)http://www.linuxidc.com/Linux/2017-04/142880.htm

Linux 下安装 PHP 环境并配置 Nginx 支持 php-fpm 模块  http://www.linuxidc.com/Linux/2017-05/144333.htm

Nginx 服务的 SSL 认证和 htpasswd 认证  http://www.linuxidc.com/Linux/2017-04/142478.htm

Ubuntu 16.04 上启用加密安全的 Nginx Web 服务器  http://www.linuxidc.com/Linux/2017-07/145522.htm

Linux 中安装配置 Nginx 及参数详解  http://www.linuxidc.com/Linux/2017-05/143853.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

CentOS 7.2 下 Nginx+PHP+MySQL+Memcache 缓存服务器安装配置  http://www.linuxidc.com/Linux/2017-03/142168.htm

CentOS6.9 编译安装 Nginx1.4.7  http://www.linuxidc.com/Linux/2017-06/144473.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2018-02/150722.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3057字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中