简单介绍一下他的安装及配置过程
官方网站
http://wiki.codemongers.com/Main
一、依赖的程序
1. gzip module requires zlib library
2. rewrite module requires pcre library
3. ssl support requires openssl library
二、安装
./configure
make
make install
默认安装的路径是/usr/local/nginx
更多的安装配置
./configure --prefix=/usr/local/nginx
--with-openssl=/usr/include (启用ssl)
--with-pcre=/usr/include/pcre/ (启用正规表达式)
--with-http_stub_status_module (安装可以查看nginx状态的程序)
--with-http_memcached_module (启用memcache缓存)
--with-http_rewrite_module (启用支持url重写)
三、启动及重启
启动:nginx
重启:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
测试配置文件:nginx -t
简单吧,安装,启动都比较方便。
四、配置文件
http://wiki.codemongers.com/NginxFullExample
#运行用户
2#启动进程
3worker_processes 5;
4#全局错误日志及PID文件
5error_log logs/error.log notice;
6pid logs/nginx.pid;
7#工作模式及连接数上限
8events {
9#工作模式有:select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),
10#epoll(高效模式,本例用的。适用Linux 2.6+,SuSE 8.2,),
#/dev/poll(高效模式,适用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)
11use epoll;
12worker_connections 1024;
13}
14#设定http服务器,利用它的反向代理功能提供负载均衡支持
15http {
16#设定mime类型
17include conf/mime.types;
18default_type application/octet-stream;
19#设定日志格式
20log_format main '$remote_addr - $remote_user [$time_local] '
21 '"$request" $status $bytes_sent '
22 '"$http_referer" "$http_user_agent" '
23 '"$gzip_ratio"';
24
25log_format download '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$http_range" "$sent_http_content_range"';
26#设定请求缓冲
27client_header_buffer_size 10k;
28large_client_header_buffers 4 4k;
29
30#开启gzip模块,要求安装gzip 在运行./config时要指定
31gzip on;
32gzip_min_length 1100;
33gzip_buffers 4 8k;
34gzip_types text/plain;
35output_buffers 1 32k;
36postpone_output 1460;
37#设定访问日志
38access_log logs/access.log main;
39client_header_timeout 3m;
40client_body_timeout 3m;
41send_timeout 3m;
42sendfile on;
43tcp_nopush on;
44tcp_nodelay on;
45keepalive_timeout 65;
46
47#设定负载均衡的服务器列表
48upstream backserver {
49#weigth参数表示权值,权值越高被分配到的几率越大
50#本例是指在同一台服务器,多台服务器改变ip即可
51server 127.0.0.1:8081 weight=5;
52server 127.0.0.1:8082;
53server 127.0.0.1:8083;
54}
#Deny access to any host other than (www).4535.com
server {
server_name _; #default
return 404;
}
55#设定虚拟主机,默认为监听80端口,改成其他端口会出现问题
56server {
57listen 80;
58server_name test.com www.test.com;
59charset utf8;
60#设定本虚拟主机的访问日志
61access_log logs/test.com.log main;
62#如果访问 /images/*, /js/*, /css/* 资源,则直接取本地文件,不用转发。但如果文件较多效果不是太好。
63location ~ ^/(images|js|css)/ {
64root /usr/local/testweb;
65expires 30m;
66}
67#对 "/" 启用负载均衡
68location / {
69proxy_pass http://backserver;
70proxy_redirect off;
71proxy_set_header Host $host;
72proxy_set_header X-Real-IP $remote_addr;
73proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
74client_max_body_size 10m;
75client_body_buffer_size 128k;
76proxy_connect_timeout 90;
77proxy_send_timeout 90;
78proxy_read_timeout 90;
79proxy_buffer_size 4k;
80proxy_buffers 4 32k;
81proxy_busy_buffers_size 64k;
82proxy_temp_file_write_size 64k;}
83#设定查看Nginx状态的地址,在运行./config 要指定,默认是不安装的。
84location /NginxStatus {
85stub_status on;
86access_log on;
87auth_basic "NginxStatus";
88#是否要通过用户名和密码访问,测试时可以不加上。conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可#auth_basic_user_file conf/htpasswd;
89}
90}
91
原文地址:http://www.blogjava.net/cenly60/archive/2008/12/12/245965.html
nginx可以很方便的配置成反向代理服务器
影响版本(nginx-1.0.10):
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://147.16.24.175:9500 ;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
}
但是如果nginx的监听端口不是默认的80端口,改为其他端口如81端口。
后端服务器中request.getServerPort()无法获得正确的端口,返回的仍然是80;
在response.sendRedirect()时,客户端可能无法获得正确的重定向url。
正确的配置方法为
在 $host之后加上端口号,如$host:81
server {
listen 83;
server_name localhost;
location / {
proxy_pass http://147.16.24.175:9500 ;
proxy_set_header Host $host:83;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
}
原文地址:http://blog.sina.com.cn/s/blog_56d8ea9001012e09.html
相关推荐
nginx 安装及配置文档包含 下载安装及相关配置步(反向代理,负载均衡)骤说明。
Nginx安装及配置笔记,步骤过程非常详细
nginx安装、配置、负载均衡
此文档详细介绍了Windows下Nginx的安装与配置,可以让用户在最短的时间内完全配置好nginx!
nginx 安装及配置实践
FastDFS+Nginx 安装及配置。FastDFS 是一个开源的轻量级分布式文件系统,纯 C 实现,支持 Linux、FreeBSD 等 UNIX 系统,FastDFS 可以看做是基于文件的 key value pair 存储系统,包含两个角色,分别为跟踪 服务器...
nginx安装及配置—负载均衡
第2章 Nginx服务器的安装与配置.pdf 第3章 Nginx的基本配置与优化.pdf 第4章 Nginx与PHP(FastCGI)的安装、配置与优化.pdf 第5章 Nginx与JSP、ASP.NET、Perl的安装与配置.pdf 第6章 Nginx HTTP负载均衡和反向代理的...
centOS8安装nginx及nginx配置
nginx的配置及安装,conf中有案例的处理的,与博客中的nginx相关的配套
使用Docker技术安装Nginx及配置简单的负载均衡。 将nginx的配置文件从容器中拷贝到宿主目录 $ mkdir -p /colorfulfrog/nginx/config --先在宿主机创建config目录 $ mkdir -p /colorfulfrog/nginx/html --先在宿主机...
Nginx的基本架构: master/worker 一个master进程,可生成一个或多个worker进程; master:加载配置文件、管理worker进程、平滑升级…… worker:如果是http请求提供http服务、http代理、fastCGI代理 事件驱动...
Ubuntu中Nginx服务器安装配置教程
此文档介绍了nginx在linux下的安装与配置,文档中包含安装时所需其他安装包的百度网盘下载地址和提取码,并附有几个安装时遇到的问题
2) Nginx配置 - 1 - a)对c:\nginx\conf\nginx.conf文件进行配置: - 1 - b)常用的 Nginx 参数 - 3 - c)静态文件处理 - 4 - d)动态页面请求处理 - 4 - e)下面为nginx.conf配置实例: - 5 - f)Nginx 启动,停止等命令 ...
nginx安装与配置详细资料+weblogic集群配置
nginx多域名配置示例 php多级域名配置 二级域名配置示例 nginx伪静态示例
提供nginx的安装配置,根据这就可傻瓜式安装配置。http节点下的upstream表示负载均衡,圆圈中的为前置机地址,提供给医院访问,方框中地址为服务端实际部署的地址(端口需一致,如果只有一个端口则只需要一个listen...
关于在linux上部署Nginx的详细讲解