In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "nginx how to proxy multiple servers", the content is detailed, the steps are clear, and the details are handled properly. I hope this "nginx how to proxy multiple servers" article can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
First modify the configuration file:
# 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 {include mime.types; default_type application/octet-stream # 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; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # gzip on; server {listen 9922; server_name firstproxyserver # charset koi8-r; # access_log logs/host.access.log main; # location / {# root html; # index index.html index.htm; #} location / {proxy_pass http://localhost:8989;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502 503 504 / 50x.hml; location = / 50x.html {root html } # proxy the php scripts to apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 proxy_pass 9000 # # location ~. Php$ {# root html; # fastcgi_pass 127.0.1 location 9000; # fastcgi_index index.php # fastcgi_param script_filename / scripts$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; #}} server {listen 9977; server_name secondproxyserver; # charset koi8-r; # access_log logs/host.access.log main; # location / {# root html # index index.html index.htm; #} location / {proxy_pass http://localhost:8080;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502 503504 / 50x.hml; location = / 50x.html {root html } # proxy the php scripts to apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 proxy_pass 9000 # # location ~. Php$ {# root html; # fastcgi_pass 127.0.1 location 9000; # fastcgi_index index.php # fastcgi_param script_filename / scripts$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; #} # another virtual host using mix of ip-, name-, and port-based configuration # # server {# listen 8000; # listen somename:8080; # server_name somename alias another.alias # location / {# root html; # index index.html index.htm; #} #} # https server # # server {# listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:ssl:1m; # ssl_session_timeout 5m; # ssl_ciphers highlands # location / {# root html; # index index.html index.htm; #} #}}
The main one is that there are two server, and each server corresponds to a different proxy server. As a result, the purpose of nginx proxy for multiple servers is realized.
The following is the configuration of the two service server:
Server {listen 9922; server_name firstproxyserver; # charset koi8-r; # access_log logs/host.access.log main; # location / {# root html; # index index.html index.htm; #} location / {proxy_pass http://localhost:8989;} # 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 html;} # proxy the php scripts to apache listening on 127.0.0.1 proxy the php scripts to apache listening on 80 # # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 root html; # location ~. Php$ {# root html; # fastcgi_pass 127.0.0.1 root html; 9000 # fastcgi_index index.php; # fastcgi_param script_filename / scripts$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; #}} server {listen 9977; server_name secondproxyserver; # charset koi8-r; # access_log logs/host.access.log main # location / {# root html; # index index.html index.htm; #} location / {proxy_pass http://localhost:8080;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502 503 504 / 50x.hml; location = / 50x.html {root html } # proxy the php scripts to apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 proxy_pass 9000 # # location ~. Php$ {# root html; # fastcgi_pass 127.0.1 location 9000; # fastcgi_index index.php # fastcgi_param script_filename / scripts$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; #}}
Here are the results of the test:
First, deploy two servers in two tomcat:
Then start nginx.
Under cmd: start nginx
Access the two server separately:
Http://localhost:9922/ngtt/
Http://localhost:9977/testnnnn/
After reading this, the article "how to proxy multiple servers with nginx" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.