• linux-nginx


    IO分为内存IO,网络IO,磁盘IO
    IO模型:
    同步IO模型:
    同步阻塞:一个进程对应一个IO,进程在运行时,不能去干别的,一直等待
    同步非阻塞:一个进程对应一个IO,进程运行时,可以去做别的事,等待别的程序的数
    据传输,进程会定时询问是否准备完成
    多路访问的IO模型--IO复用(select poll epoll)
    多线程运行
    这种情况适合大并发请求的情况,
    异步IO模型:
    *异步10*
    进程只需要发起请求,内核准备数据,当数据准备就绪以后,会主动通知进程;
    apache采用的select就是同步IO模型,而nginx采用的就是 epoll的异步模型;所以,从这点上说,nginx要远远由于apache;
    nginx适用环境:小文件的高并发传输
    nginx - engine X
    (Tengin:属于淘宝公司对nginx的=次开发优化版本,更好的支持高并发,与web安全功能);
    由俄罗斯I君开发的,2004年开发的,I君为elusive第二大网站开发的一个前端静态资源解析程序
    安装nginx
    安装nginx:
    		./configure 
    		--prefix=/usr/local/nginx  
    		--conf-path=(配置文件一定要放到程序目录下,不要放到etc目录下面去)/etc/nginx/nginx.conf  
    		--user=nginx 
    		--group=nginx 
    		--error-log-path=/var/log/nginx/error.log     // /var/log/httpd/access_log  error_log
    		--http-log-path=/var/log/nginx/access.log 
    		--pid-path=/var/run/nginx/nginx.pid 
    		--lock-path=/var/log/nginx.log 
    		--with-http_ssl_module 
    		*--with-http_stub_status_module* 
    		--with-http_gzip_static_module 
    		--with-http_flv_module 
    		--with-http_mp4_module 
    		--http-client-body-temp-path=/var/tmp/nginx/client 
    		--http-proxy-temp-path=/var/tmp/nginx/proxy 
    		--http-fastcgi-temp-path=/var/tmp/nginx/fstacgi
    		--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
    nginx.conf文件解读
    #user  nobody; ##指定Nginx Worker进程运行的用户及用户组
    worker_processes  2; ##指定了Nginx要开启的进程数
    
    #error_log  logs/error.log;  ##定义全局错误日志文件
    #error_log  logs/error.log  notice;##notice、info是输出级别
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    ##设定工作模式及连接数上限
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types; ##实现对配置文件所包含的的文件的设定,可以减少主配置文件的复杂度。
        default_type  application/octet-stream; ##设定默认类型为二进制流,
        ##指定Nginx日志的输出格式。
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
        #access_log  logs/access.log  main;
    
        sendfile        on;##开启高效文件传输模式
        #tcp_nopush     on;##
    
        #keepalive_timeout  0;##设置客户端连接保持活动的超时时间
        keepalive_timeout  65;
    
        #gzip  on;##设置开启和关闭gzip模块
    
        server { ##虚拟主机配置
            listen       80;##指定虚拟主机的服务端口
            server_name  www.whr.com; ##指定ip地址及域名
    
            #charset koi8-r;##默认字符集
    
            #access_log  logs/host.access.log  main;##指定虚拟主机的访问日志存放路径,main用于
            指定访问日志的输出格式
    
            location / {
                root   html/zero_47_zVintauge; ##返回根路径地址(相对路径:相对于/usr/local/nginx/)
                index  index.html index.htm;   ##默认访问文件
                #autoindex on;
            }
            #error_page  404              /404.html;
            # redirect server error pages to the static page /50x.html
            #错误页面极其返回地址
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #配置反向代理tomcat服务器;拦截.jsp结尾的请求转向到tomcat
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    }
    
    设置多主机名的nginx
    在http下添加一个新的server,设定新的主机名
     server {
            listen       80;
            #listen       somename:8080;
            server_name  www.welcome.com;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
        }
         server {
            listen       80;
            #listen       somename:8080;
            server_name  www.whr.com;
    
            location / {
                root   html/zero_47_zVintauge;
                index  index.html index.htm;
            }
        }
    
    然后再主机上配置hosts文件:
    10.6.29.144	www.whr
  • 相关阅读:
    Map集合
    Collection的另外一个子类LinkedList&Set集合
    多项式牛顿迭代 学习笔记
    《混凝土数学》第二章 和式 学习笔记
    洛谷P5039 最小生成树 题解
    gdfzoj#236 | 提高组练习题16 Set
    CF979E 题解
    CF1039D 题解
    CF886E 题解
    CF1061C 题解
  • 原文地址:https://www.cnblogs.com/shy13138/p/11512853.html
Copyright © 2020-2023  润新知