nginx部分

nginx的一些配置可以访问        wiki.nginx.org      里面有中文文档
tar zxf nginx-1.2.7.tar.gz
cd nginx-1.2.7
cd src/core/
查看版本
[root@server4 mysql]# curl -I 163.com HTTP/1.1 301 Moved Permanently Server: nginx Date: Tue, 11 Jun 2013 06:47:33 GMT Content-Type: text/html Content-Length: 178 Connection: keep-alive Location: http://www.163.com/
vim  nginx.h
修改这个文件,使编译之后别人查看不到nginx的版本
#define NGINX_VER          "nginx/"                                            //这行,去掉之后的NGINX_VERSION
cd ../../auto/cc/
关闭debug调试,提高性能
# debug #CFLAGS="$CFLAGS -g"
./configure --prefix=/usr/local/lanmp/nginx --with-http_ssl_module --with-http_stub_status_module
                               //指定安装路径    添加ssl模块      添加stub模块
期间可能要安装的包
yum install -y pcre-devel yum install openssl-devel -y
configure完成之后安装
make && make install
 vim ~/.bash_profile
添加nginx的环境变量
PATH=$PATH:$HOME/bin:/usr/local/lanmp/mysql/bin/:/usr/local/lanmp/nginx/sbin/
source ~/.bash_profile
nginx                    //开启服务
nginx  -t              //查看nginx配置是否有语法问题
nginx -s reload             //重新加载配置文件
nginx的一些配置
 
vim /usr/local/lanmp/nginx/conf/nginx.conf
编辑配置文件 49         location /status{                                                //在49行添加如下内容 50                 stub_status on;                                        //这个是显示nginx状态 51                 access_log  off;                                         //不生成日志
 52         }
//在浏览器输入server4.example.com/status 查看状态,每次刷新一次,里面的内容都会改变
显示结果如下
Active connections: 2 
server accepts handled requests
 11 11 281 
Reading: 0 Writing: 1 Waiting: 1
vim nginx.conf
 
worker_processes  3;            //修改nginx的进程数
events { use epoll;                                                    //提高nginx性能,在2.6内核中可以使用 worker_connections  1024;                         //设置最大链接数 }
 
配置https //将这些配置文件之前的#去掉
103     server { 104         listen       443; 105         server_name  server4.example.com;                       //可访问的域名 106 107         ssl                  on; 108         ssl_certificate      nginx.pem;                               //认证文件,这里默认是在/usr/local/lanmp/nginx/conf下 109         ssl_certificate_key  nginx.pem;                          //key文件,这里我们用成跟上面一样的文件 110 111         ssl_session_timeout  5m; 112 113         ssl_protocols  SSLv2 SSLv3 TLSv1; 114         ssl_ciphers  HIGH:!aNULL:!MD5; 115         ssl_prefer_server_ciphers   on; 116 117         location / { 118             root   html;                                                               //https默认发布目录 119             index  index.html index.htm;                                  //默认主页名字 120         } 121     }
cd /etc/pki/tls/certs/                                  //在这个目录下面生成认证文件
make nginx.pem                                         //生成认证文件 mv nginx.pem /usr/local/lanmp/nginx/conf/nginx.pem                     //将认证文件移动至刚指定的目录下
nginx -s reload                                                                                //重新加载配置文件
在浏览器输入https://server14.example.com进行验证
nginx制作虚拟目录
vim /usr/local/lanmp/nginx/conf/nginx.conf
编辑主配置文件
 
http {
: server {
: listen          80;
: server_name     www.domain1.com;
: access_log      logs/domain1.access.log main;
: location / {
: index index.html;
: root  /var/www/domain1.com/htdocs;
: }
: }
: server {
: listen          80;
: server_name     www.domain2.com;
: access_log      logs/domain2.access.log main;
: location / {
: index index.html;
: root  /var/www/domain2.com/htdocs;
: }
: }
}
在最后面的一个后括号之前添加 server{ 124         listen          80; 125         server_name     www.seven.org;                                       //域名 126         access_log      logs/seven.org.access.log main;             //日志         在上面必须开启log_format  main 127         location /{ 128                 index index.html;                                                             //默认发布文件 129                 root    /usr/local/lanmp/nginx/virtualhosts/seven.org/;            //默认发布目录 130         } 131      } 132 server{ 133         listen          80; 134         server_name     www.hello.org; 135         access_log      logs/hello.org.access.log main; 136         location /{ 137                 index index.html; 138                 root    /usr/local/lanmp/nginx/virtualhosts/hello.org/; 139         } 140      }打开log_format  main,去掉前面的注释
 22   log_format  main  '$remote_addr - $remote_user [$time_local] "$request"     ' 23                       '$status $body_bytes_sent "$http_referer" ' 24                       '"$http_user_agent" "$http_x_forwarded_for"';
nginx 的负载均衡
模板
http {
: upstream myproject {                     //其中myproject可以自己设定,是一个名字
: server 127.0.0.1:8000 weight=3;          //负载到其他的机子上面。weight使权重
: server 127.0.0.1:8001;                    //当weight越大时,轮到他的几率越大
: server 127.0.0.1:8002;
: server 127.0.0.1:8003;
: }

: server {
: listen 80;
: server_name www.domain.com;                //指定域名
: location / {
: proxy_pass http://myproject;                //指定之前的轮循规则
: }
: }
}
具体改变
 
19         upstream hello { 20                 server 192.168.0.7:80 ; 21                 server 192.168.0.144:80; 22         }49         location / {                                                                   //这里的‘/’使指访问此域后所有全部进入负载均衡 50         #    root   html; 51         #    index  index.html index.htm; 52                 proxy_pass http://hello; 53         }
 
 
 
posted @ 2013-06-17 23:29  SevenWang  阅读(178)  评论(0编辑  收藏  举报