server {
set $root_dir /var/www/edusoho;
set $webpack_server http://127.0.0.1:3030;

server_name edusoho.local;
root $root_dir/web;

error_log /var/log/nginx/edusoho_error.log;
access_log /var/log/nginx/edusoho_access.log;

location / {
    index app_dev.php;
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /app_dev.php/$1 last;
}

location ~ ^/(app_dev)\.php(/|$) {
    # fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
    fastcgi_param HTTP_X-Accel-Mapping /udisk=$root_dir/app/data/udisk;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 128k;
}

location ~ ^/udisk {
    internal;
    root $root_dir/app/data/; 
}

location ~ ^/static-dist {
    proxy_pass $webpack_server;
}

# 以下配置允许运行.php的程序,方便于其他第三方系统的集成。
location ~ \.php$ {
    # [改] 请根据实际php-fpm运行的方式修改
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTP_PROXY         "";
}

# 配置设置图片格式文件
location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
    # 过期时间为3年
    expires 3y;

    # 关闭日志记录
    access_log off;

    # 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。
    gzip off;
}

# 配置css/js文件
location ~* \.(css|js)$ {
    access_log off;
    expires 3y;
}

# 禁止用户上传目录下所有.php文件的访问,提高安全性
location ~ ^/files/.*\.(php|php5)$ {
    deny all;
}

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注