


Java cluster optimization - Nginx+tomcat cluster configuration - practice
针 Previous article, we introduced the theory of Nginx+Tomcat technical theory in the cluster. Today, let's complete a simple cluster to set up a preview.
Configuration steps:
1. Install Download the latest Nginx from the Nginx official website download page (http://nginx.org/en/download.html) version (currently 1.9 .3 version) installation package, unzip it and copy it to the deployment directory.
2. Start and stop Nginx
Nginx currently only supports command line operations. Before operating, enter the Dos command environment (cmd command) and enter the Nginx deployment directory. Start Nginx: start nginx
Stop Nginx: nginx -s stop Restart after modifying the configuration: nginx -s reloadThese three commands can be made into bat files and placed in the deployment directory to facilitate subsequent operations. Start nginx.bat file content: start nginx
Stop nginx.bat file content: nginx -s stop
reload nginx.bat file content: nginx -s reload3. Reverse proxy configuration
Modify the content of the nginx.conf file (such as nginx-1.5.13confnginx.conf) in the conf subdirectory under the deployment directory to adjust related configurations.
Reverse proxy configuration example:
location / { #设置主机头和客户端真实地址,以便服务器获取客户端真实IP proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #禁用缓存 proxy_buffering off; #设置反向代理的地址 proxy_pass http://192.168.1.1; }
By default, nginx’s upstream implements load balancing in a polling manner. In this way, each request is allocated to the server one by one in chronological order. Different backend servers can be automatically eliminated if the backend server goes down. Another method is ip_hash: each request is allocated according to the hash result of the accessed IP, so that each visitor has fixed access to a back-end server, which can solve the session problem.
Load balancing configuration exampleupstream xvshu.com{ #ip_hash; server 192.168.121.251 1; server 192.168.121.252 1; server 192.168.121.253 1; } server { listen 80 server_name trffweb; location / { #反向代理的地址 proxy_pass http://<span style="font-family: Arial, Helvetica, sans-serif;">xvshu.com</span><span style="font-family: Arial, Helvetica, sans-serif;">; </span> } }
5. Complete configuration example
nginx.conf: #Nginx所用用户和组,window下不指定 #user niumd niumd; #工作的子进程数量(通常等于CPU数量或者2倍于CPU) worker_processes 1; #错误日志存放路径 #error_log logs/error.log; #error_log logs/error.log notice; error_log logs/error.log info; #指定pid存放文件 pid logs/nginx.pid; events { #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。 #use epoll; #允许最大连接数 worker_connections 2048; } 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 off; #access_log logs/access.log; #client_header_timeout 3m; #client_body_timeout 3m; #send_timeout 3m; #client_header_buffer_size 1k; #large_client_header_buffers 4 4k; sendfile on; #tcp_nopush on; #tcp_nodelay on; keepalive_timeout 75; #include gzip.conf; upstream xvshu.cn{ #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。 #同一机器在多网情况下,路由切换,ip可能不同 #ip_hash; server 192.168.112.250:18080 weight=1; server 192.168.112.251:18080 weight=1; } server { listen 80; server_name localhost; #定义server_name localhost中的请求都叫给xvshu.cn处理 location / { #proxy_connect_timeout 3; #proxy_send_timeout 30; #proxy_read_timeout 30; proxy_pass http://xvshu.cn; proxy_redirect default; } } }
Problems encountered:
Reloading nginx service failed, prompting that there is no corresponding service, you can try to restart manually at this time Server
A good tool not only implements good functions, but more importantly, it must have simpler business logic so that users A smooth transition can only be achieved when using this tool, and Nginx is a software that exactly meets these two requirements for developers. If you don’t pay attention, users will realize it. If you pay attention, users will not realize it and cannot live without it! Isn’t this the thinking of Internet products?
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces Java cluster optimization - Nginx+tomcat cluster configuration - practice, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.

To register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

Converting an HTML file to a URL requires a web server, which involves the following steps: Obtain a web server. Set up a web server. Upload HTML file. Create a domain name. Route the request.

Troubleshooting steps for failed phpMyAdmin installation: Check system requirements (PHP version, MySQL version, web server); enable PHP extensions (mysqli, pdo_mysql, mbstring, token_get_all); check configuration file settings (host, port, username, password); Check file permissions (directory ownership, file permissions); check firewall settings (whitelist web server ports); view error logs (/var/log/apache2/error.log or /var/log/nginx/error.log); seek Technical support (phpMyAdmin
