1
2
3
|
系统版本:CentOS6. 0 X86_64
Nginx版本:Nginx- 1.2 . 6
Tomcat版本:Tomcat- 6.0 . 18
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#安装pcre支持rewrite库,也可以安装源码,注*安装源码时,指定pcre路径为解压源码的路径,而不是编译后的路径,否则会报错。 yum install pcre-devel pcre -y #下载Nginx源码包 cd /usr/src ;wget -c http: //nginx.org/download/nginx-1.2.6.tar.gz
#解压Nginx源码包 tar -xzf nginx- 1.2 . 6 .tar.gz
#进入解压目录,然后sed修改Nginx版本信息为TDTWS cd nginx- 1.2 . 6 ; sed -i -e 's/1.2.6//g' -e 's/nginx\//TDTWS/g' -e 's/"NGINX"/"TDTWS"/g' src/core/nginx.h
#预编译Nginx ./configure --user=www --group=www --prefix=/usr/local/nginx -- with -http_stub_status_module -- with -http_ssl_module
#.configure预编译成功后,执行make命令进行编译 make #make执行成功后,执行make install 正式安装 make install #自此Nginx安装完毕!!! |
#进入Nginx应用目录
cd /usr/local/nginx/conf
#备份原nginx.conf文件
mv nginx.conf nginx.bak
创建 vi nginx.conf ,并写入如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
user www www; worker_processes 8 ;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 ;
pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 102400 ;
events { use epoll;
worker_connections 102400 ;
} http { include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
charset utf- 8 ;
server_names_hash_bucket_size 128 ;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60 ;
tcp_nodelay on;
client_body_buffer_size 512k;
proxy_connect_timeout 5 ;
proxy_read_timeout 60 ;
proxy_send_timeout 5 ;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1 ;
gzip_comp_level 2 ;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_ var y on;
### 2012 - 12 - 19 change nginx logs
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time $remote_addr' ;
#这里为后端服务器wugk应用集群配置,根据后端实际情况修改即可,tdt_wugk为负载均衡名称,可以任意指定 #但必须跟vhosts.conf虚拟主机的pass段一致,否则不能转发后端的请求。 upstream tdt_wugk { server 10.10 . 141.30 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.30 : 8081 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.31 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.31 : 8081 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.32 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.32 : 8081 weight=1max_fails=2fail_timeout=30s;
} #这里为后端APP应用负载均衡配置,根据后端实际情况修改即可。tdt_app为负载均衡名称,可以任意指定 upstream tdt_app { server 10.10 . 141.40 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.40 : 8081 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.41 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.41 : 8081 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.42 : 8080 weight=1max_fails=2fail_timeout=30s;
server 10.10 . 141.42 : 8081 weight=1max_fails=2fail_timeout=30s;
} # include 引用vhosts.conf,该文件主要用于配置Nginx 虚拟主机
include vhosts.conf;
} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
####www.wuguangke.cn server {
listen 80 ;
server_name www.wuguangke.cn;
index index.html index.htm;
#配置发布目录为/data/www/wugk root /data/www/wugk;
location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
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: //tdt_wugk;
expires 3d;
}
#动态页面交给http: //tdt_wugk,也即我们之前在nginx.conf定义的upstream tdt_wugk 均衡
location ~ .*\.(php|jsp|cgi)?$
{
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: //tdt_wugk;
}
#配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /data/www/wugk;
#expires定义用户浏览器缓存的时间为 3 天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 3d;
}
#定义Nginx输出日志的路径 access_log /data/logs/nginx_wugk/access.log main;
error_log /data/logs/nginx_wugk/error.log crit;
} ##########chinaapp.sinaapp.com 2012 - 12 - 19
server
{
listen 80 ;
server_name chinaapp.sinaapp.com;
index index.html index.htm;
root /data/www;
location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
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: //tdt_app;
expires 3d;
}
location ~ .*\.(php|jsp|cgi)?$
{
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: //tdt_app;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /data/www/app;
expires 3d;
}
access_log /data/logs/nginx_app/access.log main;
error_log /data/logs/nginx_app/error.log crit;
} |
1
2
3
4
5
6
7
8
|
#检查Nginx配置文件是否配置正确,提示Ok and successful表示正确,如下: [root@WEB- 11 - 151 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#启动Nginx服务 /usr/local/nginx/sbin/nginx #查看Nginx进程是否启动 ps -ef |grep nginx |
相关推荐
nginx配置优化+负载均衡+动静分离详解
NULL 博文链接:https://lpyyn.iteye.com/blog/2224379
nginx动静分离.pdf
Nginx动静分离URL转发实战
文章目录前言:一、Nginx+Apache动静分离原理1.1 Nginx动静分离概述1.3 Nginx实现动静分离配置1.3.1 动静分离需求1.3.2 配置重点二、Nginx+Apache动静分离(实验)2.1 搭建LAMP架构2.1.1 Apache服务安装与配置2.1.2 ...
【LINUX】Nginx + Tomcat 动静分离实现负载均衡【LINUX】Nginx + Tomcat 动静分离实现负载均衡
主要介绍了Nginx动静分离实现案例代码解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
第九讲Nginx动静分离URL转发实战.pptx
Nginx Tomcat实现动静分离 就目前来说是Nginx结合Tomcat 比较好的一篇负载均衡应用文档
nginx动静分离
小型网站上进行的nginx+tomcat负载均衡与动静分离
Nginx动静分离、压缩、缓存、黑白名单、跨域、高可用、性能优化详解.docx
Nginx配置负载均衡、配置网页数据动静分离、请求日志打印详细配置、日志自动切割、自动压缩、自动删除
当网站的访问量达到一定程度后,单台服务器不能满足用户的请求时,需要用多台服务器集群可以使用 nginx 做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况。
nginx 配置 , 动静分离 及项目部署, 动态资源配置, 及 静态资源配置, 主要操作的是windows操作系统
Linux+nginx+php+mysql+memcache服务器...第10章 Nginx在国内知名网站中的应用案例.pdf 第11章 Nginx的非典型应用实例.pdf 第12章 Nginx的核心模块.pdf 第13章 Nginx的标准HTTP模块.pdf 第14章 Nginx的其他HTTP模块.pdf
Nginx动静分离介绍 Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术 针对PHP的动静分离 静态页面交给Nginx处理 动态页面交给PHP-FPM模块或Apache处理 在Nginx的配置中,是通过...
利用Nginx实现动静分离和负载均衡图文并茂!