nginx from installation to use
- From entry to proficiency
-
- Go to the official website to download and install the Windows version of the nginx package-[nginx official website](http://nginx.org/en/download.html)
- load balancing
- We need to search for some nginx commands to test whether it works or not
- How to see what services a website uses
- as the picture shows
- It's really simple, it's too simple
- nginx configuration template
From entry to proficiency
Nginx is something that cannot be bypassed in the development process. It is mainly used as a reverse proxy. If we have multiple servers, nginx can play an intermediate coordination role. The front end can freely access the resources of each server through configuration. To proxy—a proxy server, it is common in daily development to allow the front-end to complete cross-domain and successfully access the back-end interface. In fact, it is to forward the original backend request after the local server request, and the forwarded request is a request that has completed the proxy and can normally obtain the returned information
Go to the official website to download and install the nginx package of the windows version- nginx official website
Install to the root directory of the D drive, use the cmd command line to enter nginx.exe in the relevant path and press Enter to start, and enter http://localhost:80 in the browser to see the welcome page of nginx.
load balancing
That is, when we have multiple servers, we can specify the weight value of each server, so that the user's first and second visits are the first server, and the third visit is the second, reducing server pressure and handling high concurrency problem, make more reasonable use of the server.
Through some other configurations, it is also possible to directly access the second server after the first server fails to prevent the occurrence of 'hanging'
We need to search for some nginx commands to test whether it works or not
From starting ./nginx to configuring new content or setting a proxy in the config file, using the reload command to restart after modifying the port number, etc. There are many instructions, you can remember a few basic ones first, and then slowly learn to remember
How to see what services a website uses
Most of the servers that view the interface response headers are nginx or nginx-based proxies
What are the codes written in the nginx.conf file ——server
For proxy configuration, write some jump addresses for call success and failure, write some domain names and ports you want to proxy, and achieve the effect we want
There are indeed a lot of pitfalls, and if you don’t pay attention, you will report an error. I have encountered any parsing resource errors or redirect errors.
as the picture shows
picture:
This place -location is to specify the address of the page resource to be parsed, / is matched with / on the path, and it will automatically jump to this address
It's really simple, it's too simple
nginx configuration template
#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;
client_max_body_size 10m;
underscores_in_headers on;
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
#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;
resolver 8.8.8.8 ipv6=off;
sendfile on;
#tcp_nopush on;
gzip on; #开启gzip压缩功能
gzip_min_length 10k; #设置允许压缩的页面最小字节数; 这里表示如果文件小于10个字节,就不用压缩,因为没有意义,本来就很小.
gzip_buffers 4 16k; #设置压缩缓冲区大小,此处设置为4个16K内存作为压缩结果流缓存
gzip_http_version 1.1; #压缩版本
gzip_comp_level 2; #设置压缩比率,最小为1,处理速度快,传输速度慢;9为最大压缩比,处理速度慢,传输速度快; 这里表示压缩级别,可以是0到9中的任一个,级别越高,压缩就越小,节省了带宽资源,但同时也消耗CPU资源,所以一般折中为6
gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 9000;
server_name jz.wiseweb.com.cn;
#access_log logs/host.access.log main;
root /dist;
index index.html;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #保留代理之前的真实客户端ip
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 添加头部信息
proxy_set_header X-real-ip $remote_addr;
#服务
location /cbrc/dork/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods *;
proxy_pass http://122.14.231.20:952/cbrc_dork_test/dork/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
#分享
location /cbrc/api/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods *;
proxy_pass http://122.14.231.20:952/cbrc_dork_test/api/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
#报告
location /cbrc/report/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods *;
proxy_pass http://122.14.231.20:952/report_center/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
#用户中心
location /cbrc/user_center/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods *;
proxy_pass http://122.14.231.20:952/user_center/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
#文件中心
location /cbrc/file/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods *;
proxy_pass http://122.14.231.20:952/file_center/file/;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
location ^~/cbrc/group {
#proxy_pass http://47.93.77.199:8080/group;
proxy_pass http://122.14.231.200:8888/group;
}
location ^~/group {
proxy_pass http://122.14.231.200:8888/group;
}
}
}