鼎鼎知识库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

09静态资源服务器.md 1.8KB

确定网站目录:/var/www/publishapplication/d1.xyz/html
树形查看:  tree /var/www/publishapplication/d1.xyz/html
打开编辑:sudo nano /etc/nginx/sites-available/default


server {
        listen 5008;
        server_name other;
        location / {
                alias /var/www/publishapplication/d1.xyz/html/;
                index index.html;
                try_files $uri $uri/ /index.html;
        }
}


在本地和控制台都允许端口:sudo ufw allow 5008
确认语法:nginx -t
重新加载:nginx -s reload
确认gizp是否打开:sudo nano /etc/nginx/nginx.conf
	gzip on;
	gzip_min_length 1;
	gzip_comp_level 2;
	gzip_types text/plain applicaiton/x-javascript text/css application/xml text/javascript applicaiton/x-http-php image/jpeg image/gif image/png;

开放目录和文件

sudo nano /etc/nginx/sites-available/default


server {
        listen 5008;
        server_name other;
        location / {
                alias /var/www/publishapplication/d1.xyz/html/;
                autoindex on;
                index index.html;
                try_files $uri $uri/ /index.html;
        }
}

当有并发产生,让Nginx控制响应频率。

sudo nano /etc/nginx/sites-available/default


server {
        listen 5008;
        server_name other;
        location / {
                alias /var/www/publishapplication/d1.xyz/html/;
                autoindex on;
                index index.html;
                set $limit_rate 1k;
                try_files $uri $uri/ /index.html;
        }
        
}

记录日志

查看配置:sudo nano /etc/nginx/nginx.conf
确认日志文件:
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

log format main '$remote_addr' --不同域名可以不同日志记录
access_log /var/log/nginx/access.log main;