nginx configuration instructions

nginx configuration instructions


Let me talk about an example first: I put the two files in the
/ home / cubigdata / dds_softpark / excel directory, which cannot be accessed through the ip + full path.
Reason: You cannot directly access static files, you need to use nginx or apache or other web servers to proxy.
Improvement: Put the file under: / home / cubigdata / dds_softpark / front / dist / excle_tm to pass (direct access to static files, ie download), the reason is nginx agent:

http://192.168.61.148:2000/excle_tm/Tianfu Software Park-Girl Dance Template.xml

See his direction clearly: ip + port, enter server {
}
excle_tm does not match the location, then return to the root content / home / cubigdata / dds_softpark / front / dist
, which is the full path of nginx proxy access: http: //192.168 .61.148: 2000 / home / cubigdata / dds_softpark / front / distexcle_tm / Tianfu Software Park-girl dance template.xml;

Front-end interface access (http://192.168.61.148:2000/dds/web/attract/investment/financing_trade/list)

The first dds is the dds of the matched location, location / dds / {} The
second web is the routing path in the gateway, and the actual interface address is attract / investment / financing_trade / list

 server {
	#监听端口
       listen       2000;
	   #server_name(对应用户请求中的主机域名)
       server_name  dds;
	   #root:静态文件根目录访问路径,可相对也可绝对路径
       root  /home/cubigdata/dds_softpark/front/dist;
	   #index:首页的索引文件以下按顺序匹配
       index index.html login.html;
 # location块用于匹配网页位置,/可以匹配所有请求
       location /dds/ {
          proxy_pass   http://192.168.61.148:3002/;
          proxy_send_timeout 3600;
          proxy_read_timeout 3600;
          proxy_connect_timeout 3600;
       }

       location /pdf/ {
	   #此配置项将当前请求反向代理到URL参数指定的服务器上,URL可以是主机名或IP地址 加端口的形式
          proxy_pass   http://192.168.61.148:3003/;
		  #设置了发送请求给upstream服务器的超时时间。超时设置不是为了整个发送期间,而是在两次write操作期间。如果超时后,upstream没有收到新的数据,nginx会关闭连接
          proxy_send_timeout 3600;
		  #设置与代理服务器的读超时时间。它决定了nginx会等待多长时间来获得请求的响应。这个时间不是获得整个response的时间,而是两次reading操作的时间
          proxy_read_timeout 3600;
		  #设置与upstream server的连接超时时间,有必要记住,这个超时不能超过75秒。
		  #这个不是等待后端返回页面的时间,那是由proxy_read_timeout声明的。如果你的upstream服务器起来了,
		  #但是hanging住了(例如,没有足够的线程处理请求,所以把你的请求放到请求池里稍后处理),
		  #那么这个声明是没有用的,因为与upstream服务器的连接已经建立了。
          proxy_connect_timeout 3600;
       }
    }

The principle of the proxy path here:
http://192.168.61.148:2000/excle_tm/Tianfu Software Park-Girl Dance Template.xml

listen 2000;
#server_name (corresponding to the host domain name in the user request)
server_name dds;
#root: static file root directory access path, relative or absolute path
root / home / cubigdata / dds_softpark / front / dist;

192.168.61.148:2000 through the proxy root as / home / cubigdata / dds_softpark / front / dist
can be understood as 192.168.61.148:2000 / home / cubigdata / dds_softpark / front / dist / excle_tm / Tianfu Software Park-girl dance template.xml
is just Can't access directly, need nginx to proxy.
Here we have to discuss the configuration and significance of /etc/nginx/nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
#反向代理(reverse proxy)方式是指用代理服务器来接受Internet上的连接请求,然后将 请求转发给内部网络中的上游服务器,
#并将从上游服务器上得到的结果返回给Internet上请求 连接的客户端,此时代理服务器对外的表现就是一个Web服务器

# #定义Nginx运行的用户和用户组
#  如果user指令不配置或者配置为user nobody nobody,默认由nobody账户运行
user root;
#Nginx worker进程个数
worker_processes auto;
#错误日志的存放路径
error_log /var/log/nginx/error.log;
#Nginx进程PID存放路径
pid /run/nginx.pid;

# include是个主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度
include /usr/share/nginx/modules/*.conf;
#events事件指令是设定Nginx的工作模式及连接数上限
events {
#每个worker的最大连接数
    worker_connections 1024;
}

#Nginx对HTTP服务器相关属性的配置,设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
# log_format 是Nginx的HttpLog模块指令,用于指定Nginx日志的输出格式
    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  /var/log/nginx/access.log  main;
	#sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on
    sendfile            on;
	 #此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用
    tcp_nopush          on;
	#确定对keepalive连接是否使用TCP_NODELAY选项。
    tcp_nodelay         on;
	#长连接超时时间,单位是秒,一个keepalive连接在闲置超过一定时间后(默认的是75秒),服务器和浏览器都会去关 闭这个连接
    keepalive_timeout   65;
	#types_hash_max_size影响散列表的冲突率。types_hash_max_size越大,就会消耗更多的内 存,但散列key的冲突率会降低,检索速度就更快。types_hash_max_size越小,消耗的内存就 越小,但散列key的冲突率可能上升
    types_hash_max_size 2048;
	# #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
    fastcgi_connect_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_read_timeout 3600;
	#文件扩展名与文件类型映射表
    include             /etc/nginx/mime.types;
	#default_type属于HTTP核心模块指令,这里设定默认类型为二进制流,也就是当文件类型未定义时使用这种方式
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
       listen 7000;
       server_name  localhost;

       root  /home/cubigdata/softpark_screen/front/dist;
       index index.html;

       location /softpark-screen-web/ {
                proxy_pass http://192.168.61.148:5000;
       }
    }
#通过server块来定义 虚拟主机,每个server块就是一个虚拟主机,它只处理与之相对应的主机域名请求,server_name(对应用户请求中的主机域名)
    server {
	#监听端口
       listen       2000;
	   #server_name(对应用户请求中的主机域名)
       server_name  dds;
	   #root:静态文件根目录访问路径,可相对也可绝对路径
       root  /home/cubigdata/dds_softpark/front/dist;
	   #index:首页的索引文件以下按顺序匹配
       index index.html login.html;
 # location块用于匹配网页位置,/可以匹配所有请求
       location /dds/ {
          proxy_pass   http://192.168.61.148:3002/;
          proxy_send_timeout 3600;
          proxy_read_timeout 3600;
          proxy_connect_timeout 3600;
       }

       location /pdf/ {
	   #此配置项将当前请求反向代理到URL参数指定的服务器上,URL可以是主机名或IP地址 加端口的形式
          proxy_pass   http://192.168.61.148:3003/;
		  #设置了发送请求给upstream服务器的超时时间。超时设置不是为了整个发送期间,而是在两次write操作期间。如果超时后,upstream没有收到新的数据,nginx会关闭连接
          proxy_send_timeout 3600;
		  #设置与代理服务器的读超时时间。它决定了nginx会等待多长时间来获得请求的响应。这个时间不是获得整个response的时间,而是两次reading操作的时间
          proxy_read_timeout 3600;
		  #设置与upstream server的连接超时时间,有必要记住,这个超时不能超过75秒。
		  #这个不是等待后端返回页面的时间,那是由proxy_read_timeout声明的。如果你的upstream服务器起来了,
		  #但是hanging住了(例如,没有足够的线程处理请求,所以把你的请求放到请求池里稍后处理),
		  #那么这个声明是没有用的,因为与upstream服务器的连接已经建立了。
          proxy_connect_timeout 3600;
       }
    }
	#负载均衡配置
    upstream piao.jd.com {
     
        #upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。
        server 192.168.80.121:80 weight=3;
        server 192.168.80.122:80 weight=2;
        server 192.168.80.123:80 weight=3;

        #nginx的upstream目前支持4种方式的分配
        #1、轮询(默认)
        #每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
        #2、weight
        #指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
        #例如:
        #upstream bakend {
        #    server 192.168.0.14 weight=10;
        #    server 192.168.0.15 weight=10;
        #}
        #2、ip_hash
        #每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
        #例如:
        #upstream bakend {
        #    ip_hash;
        #    server 192.168.0.14:88;
        #    server 192.168.0.15:80;
        #}
        #3、fair(第三方)
        #按后端服务器的响应时间来分配请求,响应时间短的优先分配。
        #upstream backend {
        #    server server1;
        #    server server2;
        #    fair;
        #}
        #4、url_hash(第三方)
        #按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
        #例:在upstream中加入hash语句,server语句中不能写入weight等其他的参数,hash_method是使用的hash算法
        #upstream backend {
        #    server squid1:3128;
        #    server squid2:3128;
        #    hash $request_uri;
        #    hash_method crc32;
        #}

        #tips:
        #upstream bakend{#定义负载均衡设备的Ip及设备状态}{
        #    ip_hash;
        #    server 127.0.0.1:9090 down;
        #    server 127.0.0.1:8080 weight=2;
        #    server 127.0.0.1:6060;
        #    server 127.0.0.1:7070 backup;
        #}
        #在需要使用负载均衡的server中增加 proxy_pass http://bakend/;

        #每个设备的状态设置为:
        #1.down表示单前的server暂时不参与负载
        #2.weight为weight越大,负载的权重就越大。
        #3.max_fails:允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream模块定义的错误
        #4.fail_timeout:max_fails次失败后,暂停的时间。
        #5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

        #nginx支持同时设置多组的负载均衡,用来给不用的server来使用。
        #client_body_in_file_only设置为On 可以讲client post过来的数据记录到文件中用来做debug
        #client_body_temp_path设置记录文件的目录 可以设置最多3层目录
        #location对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡
    }

}
Published 67 original articles · Liked12 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/m0_37635053/article/details/104042784