The project development is coming to an end, and we have begun to deploy projects in the production environment. Nginx is useless to deploy projects in the development stage. The project adopts SOA architecture and is developed in multiple systems, mainly including service systems, middle-end systems, back-end systems, financial systems, interface systems, scheduling systems, reporting systems, etc. This type of distributed system generally uses nginx for load balancing.
Since the company was established, I came in and started to work as an architect, responsible for all the company's R&D affairs, and built the company's entire technical architecture. At the beginning, all the core business codes were basically checked and encoded by myself. The system has also developed from the initial one PC terminal to now 3 apps, including the middle platform, backend, and Android terminal, and iOS terminal. The more products are made, I personally responsible for recruitment interviews and training. I have been helpless and distressed many times before, because I am responsible for the entire company's architecture, and the coding of core business, the overcoming of technical difficulties, the recruitment and training of new employees. Now the team has grown to 16 people, and they are all R&D personnel.
Looking back on the journey, I feel that the mountain that seemed to be unable to climb before was just like this. Maybe this is growth, and growth will always be accompanied by some sweat and tears. Since I am responsible for all the things of the team, I must shoulder the performance optimization of database maintenance, data migration, index building and other performance, project deployment and other things. Don’t ask me why the company does not have a DBA? Why is there no operation and maintenance? I can only give you a look and let you experience it slowly.
Without further ado, just start sharing technical information.
The advantages of nginx for load balancing are a lot of introduction materials on the Internet, and I will not introduce them here. Because there are many systems to be deployed, involving the deployment of domain names, secondary domain names, multiple domain names, etc. In actual deployment, due to lack of familiarity with nginx, we have encountered many pitfalls, among which the multi-domain configuration is forwarded to, access the domain name forwarded to the project in tomcat, etc., and now we will summarize a solution to the pit.
If you point this domain name to the tomcat project in port 8082, you will first talk about an episode before making this introduction. If you want to access it, you need to turn to, many people will ignore this.
Now if you want to deploy the middle platform, backend, and financial system, find nginx/conf/ and modify the configuration:
upstream web{ server localhost:8082; } upstream admin{ server localhost:8083; } upstream finance{ server localhost:8084; } server { listen 80; server_name ; #charset koi8-r; #access_log logs/ main; location / { proxy_pass http://finance; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #error_page 404 /; # redirect server error pages to the static page / # error_page 500 502 503 504 /; location = / { root html; } } server { listen 80; server_name ; #charset koi8-r; #access_log logs/ main; location / { proxy_pass http://web; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #error_page 404 /; # redirect server error pages to the static page / # error_page 500 502 503 504 /; location = / { root 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 html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index ; # 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 { server_name ; rewrite ^(.*) $1 permanent; } server { listen 80; server_name ; #charset koi8-r; #access_log logs/ main; location / { proxy_pass http://admin; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #error_page 404 /; # redirect server error pages to the static page / # error_page 500 502 503 504 /; location = / { root 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 html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index ; # 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; #} }
The above configuration also includes access steeringThe configuration is as follows:
server { server_name ; rewrite ^(.*) $1 permanent; }
The basic configuration of nginx is roughly like this. If you bind multiple domain names (whether it is a first-level domain or a second-level domain), you need to configure multiple servers. You will find that the configurations of these servers are similar, mainly changing the server_name and proxy_pass pointing. The upstream node is actually the access path of the proxy service.
If you access the domain name at this time, you will find that the nginx configuration has taken effect, but the default interface of tomcat is currently displayed. This is basically the configuration of nginx. Next, some configuration modifications are made tomcat. Find conf/ in tomcat, comment out the default Host configuration, and add the following Host configuration:
<Host name="localhost" appBase="E:\tomcat\apache-tomcat-8.0.35-8082\webapps\web" deployOnStartup ="false" autoDeploy="false" unpackWARs="true"> <Context path="/" docBase="E:\tomcat\apache-tomcat-8.0.35-8082\webapps\web" /> <Valve className="" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
The above is the configuration under Windows server. If it is Linux, just change the appBase and docBase and point to the path to the project. Tomcat configuration has also been completed. Restart tomcat and access the domain name will point to the project in tomcat.
Summarize
The above is the nginx+tomcat single domain name and multiple domain name configurations introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!