高并发架构——nginx安装应用

Nginx 编译安装配置

一、安装编译需要的软件依赖
gcc gcc-c++
yum install -y gcc gcc-c ++
二、安装 Nginx 依赖
pcre-devel openssl-devel zlib-devel
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
三、创建 Nginx 用户
useradd -s /bin/false -M nginx
四、下载 Nginx 源码
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxf nginx-1.12.0.tar.gz
五、 Nginx 编译安装
## 生成 make 文件
./configure --user = nginx --group = nginx --prefix = /etc/nginx-1.12.0 --with-http_v2_module --with-
http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-
http_gzip_static_module --with-pcre
## 编译并安装
make && make install
## 添加软连接
ln -s /etc/nginx-1.12.0/ /etc/nginx
## 添加环境变量
ln -s /etc/nginx/sbin/* /usr/local/sbin/
六、 Nginx 目录介绍
├── conf # 配置文件目录
│ ├── fastcgi.conf
│ ├── fastcgi.conf.default
│ ├── fastcgi_params
│ ├── fastcgi_params.default #fastcgi * 配合 php
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types #mime 媒体类型
│ ├── mime.types.default
│ ├── nginx.conf #nginx 主配置文件
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── html # 默认站点目录
│ ├── 50x.html
│ └── index.html
├── logs # 访问日志、错误日志、 pid 文件目录 七、 Nginx 配置文件详解
│ ├── access.log # 访问日志
│ ├── error.log # 错误日志
│ └── nginx.pid #pid 文件
└── sbin # 命令目录
└── nginx #nginx 命令文件
七、 Nginx 配置文件详解
# 定义 Nginx 运行的用户和用户组
user www www;
#nginx 进程数,建议设置为等于 CPU 总核心数。
worker_processes 8 ;
# 全局错误日志定义类型, [ debug | info | notice | warn | error | crit ]
error_log /usr/local/nginx/logs/error.log info;
# 进程 pid 文件
pid /usr/local/nginx/logs/nginx.pid;
# 指定进程可以打开的最大描述符:数目
# 工作模式与连接数上限
# 这个指令是指当一个 nginx 进程打开的最多文件描述符数目,理论值应该是最多打开文件数( ulimit -n )与 nginx 进程
数相除,但是 nginx 分配请求并不是那么均匀,所以最好与 ulimit -n 的值保持一致。
# 现在在 linux 2.6 内核下开启文件打开数为 65535 worker_rlimit_nofile 就相应应该填写 65535
# 这是因为 nginx 调度时分配请求到进程并不是那么的均衡,所以假如填写 10240 ,总并发量达到 3-4 万时就有进程可能超
10240 了,这时会返回 502 错误。
worker_rlimit_nofile 65535 ;
events
{
# 参考事件模型, use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll 模型
# Linux 2.6 以上版本内核中的高性能网络 I/O 模型, linux 建议 epoll ,如果跑在 FreeBSD 上面,就用 kqueue
型。
# 补充说明:
# apache 相类, nginx 针对不同的操作系统,有不同的事件模型
#A )标准事件模型
#Select poll 属于标准事件模型,如果当前系统不存在更有效的方法, nginx 会选择 select poll
#B )高效事件模型
#Kqueue :使用于 FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 MacOS X. 使用双处理器的 MacOS X 系统使用
kqueue 可能会造成内核崩溃。
#Epoll :使用于 Linux 内核 2.6 版本及以后的系统。
#/dev/poll :使用于 Solaris 7 11/99+ HP/UX 11.22+ (eventport) IRIX 6.5.15+ Tru64 UNIX
5.1A+
#Eventport :使用于 Solaris 10 。 为了防止出现内核崩溃的问题, 有必要安装安全补丁。
use epoll;
# 单个进程最大连接数(最大连接数 = 连接数 * 进程数)
# 根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把 cpu 跑到 100% 就行。每个进程允许的最多连接数,
理论上每台 nginx 服务器的最大连接数为。
worker_connections 65535 ;
#keepalive 超时时间。
keepalive_timeout 60 ;
# 客户端请求头部的缓冲区大小。这个可以根据你的系统分页大小来设置,一般一个请求头的大小不会超过 1k ,不过
由于一般系统分页都要大于 1k ,所以这里设置为分页大小。
# 分页大小可以用命令 getconf PAGESIZE 取得。
#[root@web001 ~]# getconf PAGESIZE
#4096
# 但也有 client_header_buffer_size 超过 4k 的情况,但是 client_header_buffer_size 该值必须设置为 系统分
页大小 的整倍数。
client_header_buffer_size 4k;
# 这个将为打开文件指定缓存,默认是没有启用的, max 指定缓存数量,建议和打开文件数一致, inactive 是指经过
多长时间文件没被请求后删除缓存。
open_file_cache max = 65535 inactive = 60s;
# 这个是指多长时间检查一次缓存的有效信息。
# 语法 :open_file_cache_valid time 默认值 :open_file_cache_valid 60 使用字段 :http, server,
location 这个指令指定了何时需要检查 open_file_cache 中缓存项目的有效信息 .
open_file_cache_valid 80s;
#open_file_cache 指令中的 inactive 参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在
缓存中打开的,如上例,如果有一个文件在 inactive 时间内一次没被使用,它将被移除。
# 语法 :open_file_cache_min_uses number 默认值 :open_file_cache_min_uses 1 使用字段 :http, server,
location 这个指令指定了在 open_file_cache 指令无效的参数中一定的时间范围内可以使用的最小文件数 , 如果使用
更大的值 , 文件描述符在 cache 中总是打开状态 .
open_file_cache_min_uses 1 ;
# 语法 :open_file_cache_errors on | off 默认值 :open_file_cache_errors off 使用字段 :http, server,
location 这个指令指定是否在搜索一个文件是记录 cache 错误 .
open_file_cache_errors on;
}
# 设定 http 服务器,利用它的反向代理功能提供负载均衡支持
http
{
# 文件扩展名与文件类型映射表
include mime.types;
# 默认文件类型
default_type application/octet-stream;
# 默认编码
#charset utf-8;
# 服务器名字的 hash 表大小
# 保存服务器名字的 hash 表是由指令 server_names_hash_max_size server_names_hash_bucket_size 所控制
的。参数 hash bucket size 总是等于 hash 表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数
后,使在处理器中加速查找 hash 表键值成为可能。如果 hash bucket size 等于一路处理器缓存的大小,那么在查找键的
时候,最坏的情况下在内存中查找的次数为 2 。第一次是确定存储单元的地址,第二次是在存储单元中查找键 值。因
此,如果 Nginx 给出需要增大 hash max size hash bucket size 的提示,那么首要的是增大前一个参数的大小 .
server_names_hash_bucket_size 128 ;
# 客户端请求头部的缓冲区大小。这个可以根据你的系统分页大小来设置,一般一个请求的头部大小不会超过 1k ,不
过由于一般系统分页都要大于 1k ,所以这里设置为分页大小。分页大小可以用命令 getconf PAGESIZE 取得。
client_header_buffer_size 32k;
# 客户请求头缓冲大小。 nginx 默认会用 client_header_buffer_size 这个 buffer 来读取 header 值,如果 header
过大,它会使用 large_client_header_buffers 来读取。
large_client_header_buffers 4 64k;
# 设定通过 nginx 上传文件的大小
client_max_body_size 8m;
# 开启高效文件传输模式, sendfile 指令指定 nginx 是否调用 sendfile 函数来输出文件,对于普通应用设为 on ,如
果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off ,以平衡磁盘与网络 I/O 处理速度,降低系统的负载。注意:如
果图片显示不正常把这个改成 off
#sendfile 指令指定 nginx 是否调用 sendfile 函数( zero copy 方式)来输出文件,对于普通应用,必须设为
on 。如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off ,以平衡磁盘与网络 IO 处理速度,降低系统 uptime
sendfile on;
# 开启目录列表访问,合适下载服务器,默认关闭。
autoindex on;
# 此选项允许或禁止使用 socke TCP_CORK 的选项,此选项仅在使用 sendfile 的时候使用
tcp_nopush on;
tcp_nodelay on;
# 长连接超时时间,单位是秒
keepalive_timeout 120 ;
#FastCGI 相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
fastcgi_connect_timeout 300 ;
fastcgi_send_timeout 300 ;
fastcgi_read_timeout 300 ;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#gzip 模块设置
gzip on; # 开启 gzip 压缩输出
gzip_min_length 1k; # 最小压缩文件大小
gzip_buffers 4 16k; # 压缩缓冲区
gzip_http_version 1 .0; # 压缩版本(默认 1.1 ,前端如果是 squid2.5 请使用 1.0
gzip_comp_level 2 ; # 压缩等级
gzip_types text/plain application/x-javascript text/css application/xml; # 压缩类型,默认就
已经包含 textml ,所以下面就不用再写了,写上去也不会有问题,但是会有一个 warn
gzip_vary on;
# 开启限制 IP 连接数的时候需要使用
#limit_zone crawler $binary_remote_addr 10m;
# 负载均衡配置
upstream carlosxiao.cc {
#upstream 的负载均衡, weight 是权重,可以根据机器配置定义权重。 weigth 参数表示权值,权值越高被分配
到的几率越大。
server 192 .168.13.43:8080 weight = 3 ;
server 192 .168.13.44:8080 weight = 2 ;
#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 进行匹配 . 可以进行重定向或者进行新的代理 负载均衡
}
# 虚拟主机的配置
server
{
# 监听端口
listen 80 ;
# 域名可以有多个,用空格隔开
server_name www.carlosxiao.cc carlosxiao.cc;
index index.html index.htm index.php;
root /data/www;
# ****** 进行负载均衡
location ~ .*.(php|php5)? $
{
fastcgi_pass 127 .0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# 图片缓存时间设置
location ~ .*.(gif|jpg|jpeg|png|bmp|swf) $
{
expires 10d;
}
#JS CSS 缓存时间设置
location ~ .*.(js|css)? $
{
expires 1h;
}
# 日志格式设定
#$remote_addr $http_x_forwarded_for 用以记录客户端的 ip 地址;
#$remote_user :用来记录客户端用户名称;
#$time_local : 用来记录访问时间与时区;
#$request : 用来记录请求的 url http 协议;
#$status : 用来记录请求状态;成功是 200
#$body_bytes_sent :记录发送给客户端文件主体内容大小;
#$http_referer :用来记录从那个页面链接访问过来的;
#$http_user_agent :记录客户浏览器的相关信息;
# 通常 web 服务器放在反向代理的后面,这样就不能获取到客户的 IP 地址了,通过 $remote_add 拿到的 IP 地址是
反向代理服务器的 iP 地址。反向代理服务器在转发请求的 http 头信息中,可以增加 x_forwarded_for 信息,用以记录原
有客户端的 IP 地址和原来客户端的请求的服务器地址。
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for' ;
# 定义本虚拟主机的访问日志
access_log /usr/local/nginx/logs/host.access.log main;
access_log /usr/local/nginx/logs/host.access.404.log log404;
# "/" 启用反向代理
location / {
proxy_pass http://127.0.0.1:88;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr ;
# 后端的 Web 服务器可以通过 X-Forwarded-For 获取用户真实 IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
# 以下是一些反向代理的配置,可选。
proxy_set_header Host $host ;
# 允许客户端请求的最大单文件字节数
client_max_body_size 10m;
# 缓冲区代理缓冲用户端请求的最大字节数,
# 如果把它设置为比较大的数值,例如 256k ,那么,无论使用 firefox 还是 IE 浏览器,来提交任意小于
256k 的图片,都很正常。如果注释该指令,使用默认的 client_body_buffer_size 设置,也就是操作系统页面大小的两
倍, 8k 或者 16k ,问题就出现了。
# 无论使用 firefox4.0 还是 IE8.0 ,提交一个比较大, 200k 左右的图片,都返回 500 Internal Server
Error 错误
client_body_buffer_size 128k;
# 表示使 nginx 阻止 HTTP 应答代码为 400 或者更高的应答。
proxy_intercept_errors on;
# 后端服务器连接的超时时间 _ 发起握手等候响应超时时间
#nginx 跟后端服务器连接超时时间 ( 代理连接超时 )
proxy_connect_timeout 90 ;
# 后端服务器数据回传时间 ( 代理发送超时 )
# 后端服务器数据回传时间 _ 就是在规定时间之内后端服务器必须传完所有的数据
proxy_send_timeout 90 ;
# 连接成功后,后端服务器响应时间 ( 代理接收超时 )
# 连接成功后 _ 等候后端服务器响应时间 _ 其实已经进入后端的排队之中等候处理(也可以说是后端服务器
处理请求的时间)
proxy_read_timeout 90 ;
# 设置代理服务器( nginx )保存用户头信息的缓冲区大小
# 设置从被代理服务器读取的第一部分应答的缓冲区大小,通常情况下这部分应答中包含一个小的应答
头,默认情况下这个值的大小为指令 proxy_buffers 中指定的一个缓冲区的大小,不过可以将其设置为更小
proxy_buffer_size 4k;
#proxy_buffers 缓冲区,网页平均在 32k 以下的设置
# 设置用于读取应答(来自被代理服务器)的缓冲区数目和大小,默认情况也为分页大小,根据操作系统
的不同可能是 4k 或者 8k
proxy_buffers 4 32k;
# 高负荷下缓冲大小( proxy_buffers*2
proxy_busy_buffers_size 64k;
# 设置在写入 proxy_temp_path 时数据的大小,预防一个工作进程在传递文件时阻塞太长
# 设定缓存文件夹大小,大于这个值,将从 upstream 服务器传
proxy_temp_file_write_size 64k;
}
# 设定查看 Nginx 状态的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus" ;
auth_basic_user_file confpasswd;
#htpasswd 文件的内容可以用 apache 提供的 htpasswd 工具来产生。
}
# 本地动静分离反向代理配置
# 所有 jsp 的页面均交由 tomcat resin 处理
location ~ .(jsp|jspx|do)? $ {
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_pass http://127.0.0.1:8080;
}
# 所有静态文件由 nginx 直接读取不经过 tomcat resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|
pdf|xls|mp3|wma) $
{
expires 15d;
}
location ~ .*.(js|css)? $
{
expires 1h;
}
}
}
location 匹配模式以及顺序
location = /uri 
= 开头表示精确匹配,只有完全匹配上才能生效
location ^~ /uri  ^~ 开头对 URL 路径进行前缀匹配,并且在正则之前
location ~ pattern 
~ 开头表示区分大小写的正则匹配
location ~* pattern 
~* 开头表示不区分大小写的正则匹配
location /uri 
不带任何修饰符,也表示前缀匹配,但是在正则匹配之后
location / 
通用匹配,任何未匹配到其它 location 的请求都会匹配到,相当于 switch 中的 default
八、 Nginx 常用命令
检查配置文件
nginx -t
指定其他配置文件启动 nginx
nginx -c file
启动 nginx
nginx
停止 nginx
## 快速停止 nginx
nginx -s stop
## 平滑停止 nginx
nginx -s quit
重启 nginx
## 平滑重载所有配置
nginx -s reload
九、配置示例
web 服务器
#user nobody;
worker_processes auto;
#worker_cpu_affinity auto;
worker_rlimit_nofile 655350;
#pid logs/nginx.pid;
error_log /data/logs/nginx/error.log error;
events {
use epoll;
worker_connections 655350;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
log_format main '$remote_addr $server_addr $remote_user [$time_local] $host '
'"$request" $status $body_bytes_sent $request_time $upstream_response_time '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log /data/logs/nginx/access.log main;
sendfile on;
keepalive_timeout 90000;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 512;
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
client_header_timeout 300m;
client_body_timeout 300m;
send_timeout 300m;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 100M;
client_body_buffer_size 50m;
proxy_connect_timeout 5;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_intercept_errors on;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 256;
variables_hash_max_size 512;
variables_hash_bucket_size 128;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_comp_level 3;
gzip_http_version 1.0;
gzip_types text/plain application/x-javascript application/json application/javascript
text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
output_buffers 1 32k;
postpone_output 1460;
gzip_vary on;
map_hash_max_size 102400;
map_hash_bucket_size 256;
fastcgi_intercept_errors on;
server {
listen 80;
server_name carlosxiao.cc;
location / {
root /data/www;
index index.html index.htm;
}
access_log /data/logs/nginx/carlosxiao.log;
}
}
反向代理
#user nobody;
worker_processes auto;
#worker_cpu_affinity auto;
worker_rlimit_nofile 655350;
#pid logs/nginx.pid;
error_log /data/logs/nginx/error.log error;
events {
use epoll;
worker_connections 655350;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
log_format main '$remote_addr $server_addr $remote_user [$time_local] $host '
'"$request" $status $body_bytes_sent $request_time $upstream_response_time '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log /data/logs/nginx/access.log main;
sendfile on;
keepalive_timeout 90000;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 512;
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
client_header_timeout 300m;
client_body_timeout 300m;
send_timeout 300m;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 100M;
client_body_buffer_size 50m;
proxy_connect_timeout 5;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_intercept_errors on;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 256;
variables_hash_max_size 512;
variables_hash_bucket_size 128;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_comp_level 3;
gzip_http_version 1.0;
gzip_types text/plain application/x-javascript application/json application/javascript
text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
output_buffers 1 32k;
postpone_output 1460;
gzip_vary on;
map_hash_max_size 102400;
map_hash_bucket_size 256;
fastcgi_intercept_errors on;
upstream carlosxiao.cc{
server 192.168.13.43:8080;
server 192.168.13.44:8080;
check interval=3000 rise=2 fall=3 timeout=3000 type=http;
}
server {
listen 80;
server_name carlosxiao.cc;
location / {
proxy_pass http://carlosxiao.cc;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 60;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
access_log /data/logs/nginx/carlosxiao.log;
}
}
动静分离
#user nobody;
worker_processes auto;
#worker_cpu_affinity auto;
worker_rlimit_nofile 655350;
#pid logs/nginx.pid;
error_log /data/logs/nginx/error.log error;
events {
use epoll;
worker_connections 655350;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
log_format main '$remote_addr $server_addr $remote_user [$time_local] $host '
'"$request" $status $body_bytes_sent $request_time $upstream_response_time '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log /data/logs/nginx/access.log main;
sendfile on;
keepalive_timeout 90000;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 512;
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
client_header_timeout 300m;
client_body_timeout 300m;
send_timeout 300m;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 100M;
client_body_buffer_size 50m;
proxy_connect_timeout 5;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_intercept_errors on;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 256;
variables_hash_max_size 512;
variables_hash_bucket_size 128;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_comp_level 3;
gzip_http_version 1.0;
gzip_types text/plain application/x-javascript application/json application/javascript
text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
output_buffers 1 32k;
postpone_output 1460;
gzip_vary on;
map_hash_max_size 102400;
map_hash_bucket_size 256;
fastcgi_intercept_errors on;
upstream carlosxiao.cc{
server 127.0.0.1:10179;
}
server {
listen 80;
server_name carlosxiao.cc;
location /api {
proxy_pass http://carlosxiao.cc;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 60;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
location ~ .(jsp|jspx|do)?$ {
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_pass http://carlosxiao.cc;
}
# 所有静态文件由 nginx 直接读取不经过 tomcat resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|
pdf|xls|mp3|wma)$
{
expires 15d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
access_log /data/logs/nginx/carlosxiao.log;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

择业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值