美文网首页
nginx配置

nginx配置

作者: 哈哈新开张 | 来源:发表于2021-09-26 11:29 被阅读0次

#user  nobody;
worker_processes  4;

error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    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;
    access_log      off;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #user root; #运行身份,默认是nobody

    gzip on;
    gzip_buffers 32 4K;
    gzip_comp_level 6;
    gzip_min_length 100;
    gzip_types application/javascript text/css text/xml;
    gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
    gzip_vary on;

    # 80端口默认进入404
    server {
        listen 80;
        root /home/cq/mes/public;
        client_max_body_size 10M;

        location / {
            index  index.php index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
            }
            #proxy_connect_timeout 2; #配置nginx与后端服务器建立连接的超时时间
            #proxy_read_timeout 2; #配置nginx向后端发出read请求的等待响应超时时间
            #proxy_send_timeout 2; #配置nginx向后端服务器发出write请求的等待响应超时时间
        }

        location ~ ^(.+\.php)(.*)$ {
            fastcgi_pass            127.0.0.1:9000;
            fastcgi_split_path_info       ^(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            include fastcgi_params;
        }

        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
           expires 30d;
        }
    }

    # 至少需要一个
    upstream easyswoole {
        server 127.0.0.1:9999;
    }
    server {
        listen 80;
        server_name api.drivino.com;
        location / {
            # 将客户端host及ip信息转发到对应节点
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            # 转发Cookie,设置 SameSite
            proxy_cookie_path / "/;";

            # 代理访问真实服务器
            proxy_pass http://easyswoole;
        }
    }
}

相关文章

网友评论

      本文标题:nginx配置

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