美文网首页
Nginx常用配置

Nginx常用配置

作者: Jason_lai | 来源:发表于2020-06-16 07:51 被阅读0次
    #进程守护者:
    user  nginx;
    
    #错误日志
    error_log  logs/error.log;
    
    #pid进程信息:
    pid        logs/nginx.pid;
    
    #worker进程数:
    worker_processes  1;
    
    #每进程处理连接数:
    worker_connections  1024;
    
    #主配置区域结构:
    http{
        #mime文件类型
        include       mime.types;
    
        #默认为附件类型
        default_type  application/octet-stream;
    
        #访问日志格式
        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;
        
        #第一台http虚拟主机配置
        server{
            #端口号
            listen       80;
    
            #网站域名
            server_name  localhost;
    
            #web字符集
            #charset koi8-r;
    
            #访问日志
            #access_log  logs/host.access.log  main;
    
            #匹配192.168.2.1或192.168.2.1/
            location / {
                #设置网站根目录
                root   html;
    
                #设置默认首页
                index  index.php index.html index.htm;
            }
    
            #设置404错误页面
            #error_page  404              /404.html;
    
            #设置50x错误页面
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            #访问php文件时直接交给本机apache服务来处理
            location ~ \.php$ {
                proxy_pass   http://127.0.0.1;
            }
    
            #请求php文件时交给php-fpm处理
            location ~ \.php$ {
                fastcgi_index  index.php;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name; 
                include        fastcgi_params;
            }
    
            拒绝所有人访问.htaccess文件
            location ~ /\.ht {
                deny  all;
            }
        }
    
        #第二台http虚拟主机配置
        server {
            listen       8000;
            listen       somename:8080;
            server_name  somename  alias  another.alias;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
        }
    
        #配置https虚拟主机
        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常用配置

          本文链接:https://www.haomeiwen.com/subject/zyocxktx.html