龙空技术网

干货!详解给Nginx绑定多个端口的两种方法

波波聊运维 771

前言:

现在咱们对“nginx多个root存在时”大体比较关心,朋友们都想要知道一些“nginx多个root存在时”的相关内容。那么小编也在网摘上汇集了一些关于“nginx多个root存在时””的相关资讯,希望咱们能喜欢,看官们快快来学习一下吧!

实例介绍在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 ; 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 ; 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 ; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host:$server_port; } }}

这样就就可以一个nginx服务访问8080和8089两个端口到不同服务的了

后面小编会分享更多这方面的干货,感兴趣的朋友可以关注一下~

标签: #nginx多个root存在时