nginx的简单使用
2010-09-01 20:35
239 查看
[root@station8 ~]#yum -y --nogpgcheck localinstall nginx-0.6.39-5.el5.i386.rpm
vim /etc/nginx/nginx.conf
1.修改nginx的默认网页位置
location / {
root /web;
index index.html index.htm;
}
2.测试nginx添加虚拟主机(可定义多个主机,其中listen可为端口,ip,ip+端口,主机头)
server {
listen 8080;
location / {
root /web;
index index.html;
}
2.nginx的认证(需要使用apache的htpasswd命令)
[root@station8 ~]# yum install -y httpd
[root@station8 ~]#vim /etc/nginx/nginx.conf
location / {
root /web;
auth_basic “You need a key” #提示语
auth_basic_user_file /etc/nginx/htpasswd #指定读取的授权文件路径
index index.html index.htm;
}
创建htpasswd的文件
touch /etc/nginx/htpasswd
建立用户tom,并给与密码(不支持md5算法)
htpasswd -cd /etc/nginx/htpasswd tom
3.nginx的反向代理及负载均衡
Nginux HTTP Upstream 模块为后端的服务器提供简单的负载均衡,有以下几种分配方式:
a.轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
b.weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
c.ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
d.fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
e.url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
upstream myhttp{
server 192.168.0.66; #后端服务器1
server 192.168.0.42 weight=5; #后端服务器2
}
server {
listen 80;
server_name _;
location / {
root /web;
proxy_pass http://myhttp; #指定代理的服务(与上面设定的myhttp保持一致)
proxy_set_header X-REAL-IP $remote_addr;
#auth_basic "You need a key";
#auth_basic_user_file /etc/nginx/htpasswd;
index index.html index.htm;
}
}
本文出自 “一份存档” 博客,请务必保留此出处http://linuxbpm.blog.51cto.com/1823930/386188
vim /etc/nginx/nginx.conf
1.修改nginx的默认网页位置
location / {
root /web;
index index.html index.htm;
}
2.测试nginx添加虚拟主机(可定义多个主机,其中listen可为端口,ip,ip+端口,主机头)
server {
listen 8080;
location / {
root /web;
index index.html;
}
2.nginx的认证(需要使用apache的htpasswd命令)
[root@station8 ~]# yum install -y httpd
[root@station8 ~]#vim /etc/nginx/nginx.conf
location / {
root /web;
auth_basic “You need a key” #提示语
auth_basic_user_file /etc/nginx/htpasswd #指定读取的授权文件路径
index index.html index.htm;
}
创建htpasswd的文件
touch /etc/nginx/htpasswd
建立用户tom,并给与密码(不支持md5算法)
htpasswd -cd /etc/nginx/htpasswd tom
3.nginx的反向代理及负载均衡
Nginux HTTP Upstream 模块为后端的服务器提供简单的负载均衡,有以下几种分配方式:
a.轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
b.weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
c.ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
d.fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
e.url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
upstream myhttp{
server 192.168.0.66; #后端服务器1
server 192.168.0.42 weight=5; #后端服务器2
}
server {
listen 80;
server_name _;
location / {
root /web;
proxy_pass http://myhttp; #指定代理的服务(与上面设定的myhttp保持一致)
proxy_set_header X-REAL-IP $remote_addr;
#auth_basic "You need a key";
#auth_basic_user_file /etc/nginx/htpasswd;
index index.html index.htm;
}
}
本文出自 “一份存档” 博客,请务必保留此出处http://linuxbpm.blog.51cto.com/1823930/386188
相关文章推荐
- tomcat服务器下使用nginx实现最简单的动静分离--解决css、js不加载的问题
- 使用Docker在Nginx上运行简单的HTML网页
- 使用nginx搭建简单的文件服务器
- Nginx与tomcat组合的简单使用
- nginx的反向代理,缓存及LNMP的简单使用。
- 使用nginx搭建一个简单的负载均衡
- nginx的简单使用和使用nginx在windows上搭建tomcat集群
- Nginx专题: upstream模块和缓存的简单使用
- nginx简单双机热备:backup参数的使用
- windows下Nginx与tomcat组合简单使用
- 使用nginx简单实现负载均衡
- 使用nginx+tomcat 搭建简单的负载均衡
- nginx简单配置及使用
- Nginx使用:Ubuntu安装与简单配置
- 使用Nginx的upstream实现简单的1+2负载均衡
- 使用nginx搭建简单的文件服务器
- [Nginx]Nginx简单使用(一)
- nginx http_gzip_static_module 扩展压缩模块的简单使用
- 使用 Caddy 替代 Nginx,全站升级 https,配置更加简单
- nginx(Tengine)使用小结--安装与简单配置篇