zoukankan      html  css  js  c++  java
  • nginx配置

    一.nginx的配置文件默认在nginx程序安装目录的conf二级目录下
    主配置文件为nginx.conf
    exp: nginx安装在/usr/local/webserver/nginx/目录下
    默认主配置文件:/usr/local/webserver/nginx/nginx.conf


    二、完整配置示例

    #使用的用户和组
        user www www;
        #指定工作衍生进程数(一般等于CPU的总核数或总核数的两倍,例如两个四核CPU,则总核数为8)
        worker_process 8;
        #指定错误日志存放的路径,错误日志记录级别可选线为:[debug | info | notice | warn | error | crit]
        error_log /datal/logs/nginx_error.log crit;
        #指定pid存放的路径
        pid   /usr/local/webserver/nginx/nginx.pid
    
        #指定文件描述符数量
        worker_rlimit_nofile 51200;
    
        events
        {
        
            #使用的网络I/O模型,linux系统推荐采用epoll模型,freebsd系统推荐采用kqueue模型
            use epoll;
            #允许的连接数
            worker_connections 51200;
        
        }
    
        http
        {
            include mime.types;
            default_type application/octet-stream;
            #设置使用的字符集,如果一个网站有许多字符集,请不要随便设置,应让程序员在html代码中通过meta标签设置
            #charset gb2312;
    
            server_names_hash_bucket_size 128;
            client_header_buffer_size 32k;
            large_client_header_buffers 4 32k;
    
            #设置客户端能够上传的文件大小
            client_max_body_size 8m;
    
            sendfile on;
            tcp_nopush on;
    
            keepalive_timeout 60;
    
            tcp_nodelay on;
    
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_buffer_size 64k;
            fastcgi_buffers 4 64k;
            fastcgi_busy_buffers_size 128k;
            fastcgi_temp_file_write_size 128k;
    
            #开启gzip压缩
            gzip on;
            gzip_min_length 1k;
            gzip_buffers 4 16k;
            gzip_comp_level 2;
            gzip_types text/plain applliction/x-javascript text/css application/xml;
            gzip_vary on;
    
            #limit_zone crawler $binary_remote_addr 10m;
    
            server
            {
                listen 80;
                server_name www.yourdomain.com  yourdomain.com;
                index index.html index.htm index.php
    
                root /data0/htdocs;
    
                #limit_conn crawler 20;
    
                location ~ .*.(gif|jpg|jgeg|png|bmp|swf)$
                {
                    expires 30d;
                }
    
                location ~ .*.(js|css)?$
                {
                    expires 1h;
                }
    
                log_format access '$remote_addr - $remote_user [$time_local] "$request"'
                        '$status $body_bytes_sent "$http_referer" '
                        
                        '"$http_user_agent" $http_x_forwarded_for';
                access_log    /data/logs/access.log access;
            }
        }

    三、nginx的虚拟主机配置
    nginx可以配置多种类型的虚拟主机:
    ①。基于IP的虚拟主机
    ②。基于域名的虚拟主机
    ③。基于端口的虚拟主机

    1.配置基于IP的虚拟主机
    IP别名
    /etc/rc.local


    2.配置基于域名的虚拟主机

      aaa.domain.com
      bbb.otherdomain.com
      www.domain.com

    http
        {
            #第一个虚拟主机
            server
            {    
                #监听的端口
                listen 80;
                #主机名称
                server_name aaa.domain.com;
                #访问日志文件存放路径
                access_log logs/aaa.domain.com.access.log.combinded;
    
                location /
                {    
                    #默认首页文件,顺序从左到右,如果找不到Index.html文件,则查找index。htm文件作为首页文件
                    index index.html index.htm;
                    #html 网页文件存放的目录
                    root /data0/htdocs/aaa.domain.com;
                }
            }
    
    
            #第二个虚拟主机
            server
            {    
                #监听的端口
                listen 80;
                #主机名称
                server_name bbb.otherdomain.com;
                #访问日志文件存放路径
                access_log logs/bbb.domain.com.access.log.combinded;
    
                location /
                {    
                    #默认首页文件,顺序从左到右,如果找不到Index.html文件,则查找index.htm文件作为首页文件
                    index index.html index.htm;
                    #html 网页文件存放的目录
                    root /data0/htdocs/bbb.domain.com;
                }
            }
    
            #第三个虚拟主机
            server
            {    
                #监听的端口
                listen 80;
                #主机名称
                server_name www.domain.com domain.com *.domain.com;
                #访问日志文件存放路径
                access_log logs/bbb.domain.com.access.log.combinded;
    
                location /
                {    
                    #默认首页文件,顺序从左到右,如果找不到Index.html文件,则查找index。htm文件作为首页文件
                    index index.html index.htm;
                    #html 网页文件存放的目录
                    root /data0/htdocs/domain.com;
                }
            }
        }
    View Code
  • 相关阅读:
    linux 里 /etc/passwd 、/etc/shadow和/etc/group 文件内容解释
    IIS 7.5 配置 php 5.4.22 链接 sql 2008(用PDO链接数据库)
    如何学好一本编程语言
    从零开始学YII2.0
    android AlertDialog 错误 OnClickListener 报错
    胖哥从零开始做一个APP系列文章的通知
    引用自定义控件出现的问题
    java hashMap实现原理
    粗略读完opengl
    求知若饥,虚心若愚
  • 原文地址:https://www.cnblogs.com/suihui/p/3353267.html
Copyright © 2011-2022 走看看