Simple use of nginx

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[simple use of nginx]

[java small class of Xiuzhen academy] simple use of nginx

Hello, I'm Xu Dongjie, a student of Shanghai Branch of it Academy. I'm an honest, pure and kind java programmer. Today, I'd like to share with you the knowledge point of in-depth thinking - nginx proxy server, Java (occupation) task 2 on the official website of the Academy

(1) Background:

Load balancing:

Web is too laggy to be deployed on the server (tomcat, jetty, etc.) after the development of the project is completed. When high concurrency access is made, the server will be stuck. Load balancing means adding several servers to share these visits, thereby reducing the server pressure.

Nginx is such a proxy server for load balancing.

(2) Knowledge analysis:

Two main functions of applying nginx

Nginx: reverse proxy server, an open-source Web server written in C language, which is specialized in load balancing and static proxy. It is lightweight and can store a large amount of data.

Load balancing: in essence, nginx is also a server, which can be regarded as a general agent of other servers. When requests come, it will dynamically allocate the servers requesting access according to the configuration.

Static proxy: Tomcat will be very slow to process a large amount of picture data, so it uses nginx as the proxy to separate the dynamic and static. In this way, Tomcat can directly call the data picture on nginx

(3) Frequently asked questions:

When deploying two local servers, only one can be started

(4) Solution:

Delete the environment variable of the local Tomcat server, and then change the three ports of the second server.

(5) Coding practice:

Load balancing and static agent configuration:

#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 vhost/*. conf;# Import other profiles

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;

#Load balancing configuration

upstream localhost{

server localhost:8888 weight=1;# priority

server localhost:8889 weight=1;

}

server {

listen 80;

server_ name www.xudongjie. com;

#charset koi8-r;

#access_ log logs/host. access. log main;

location / {

#root html;

# index index. html index. htm;

proxy_ set_ header Host $host; # required for docker client's sake

proxy_ set_ header X-Real-IP $remote_ addr; # Get the user's real IP address

proxy_ set_ header X-Forwarded-For $proxy_ add_ x_ forwarded_ for;

proxy_ pass http://localhost ;

}

error_ page 500 502 503 504 /50x. html;

location = /50x. html {

root html;

}

}

server {

listen 80;

server_ name image. xudongjie. com;

root E:/Nginx/statictext/;

charset utf-8;

#access_ log logs/host. access. log main;

location / {

root E:/Nginx/statictext/;

index index. html; # You can specify the file name index html;

}

error_ page 500 502 503 504 /50x. html;

location = /50x. html {

root html;

}

}

}

(6) Expand thinking:

(7) References:

Baidu, Google

(8) More discussion:

Q1: application of static agent in practice?

A1: in practice, static picture pages are placed in the nginx server directory. When Tomcat wants to call these resources, it can directly access the nginx server for reading. Q2: questioner: is there any other way for static proxy? A2: you can separate the access pages in a host according to the suffix of the access path without using the virtual host Html is allocated to the local static library JSP is assigned to Tomcat server.

(9) Conclusion:

That's all for today's sharing. You are welcome to like, forward, leave messages and make bricks~

Ppt link video link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>