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

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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ```
  2. 确定网站目录:/var/www/publishapplication/d1.xyz/html
  3. 树形查看: tree /var/www/publishapplication/d1.xyz/html
  4. 打开编辑:sudo nano /etc/nginx/sites-available/default
  5. server {
  6. listen 5008;
  7. server_name other;
  8. location / {
  9. alias /var/www/publishapplication/d1.xyz/html/;
  10. index index.html;
  11. try_files $uri $uri/ /index.html;
  12. }
  13. }
  14. 在本地和控制台都允许端口:sudo ufw allow 5008
  15. 确认语法:nginx -t
  16. 重新加载:nginx -s reload
  17. 确认gizp是否打开:sudo nano /etc/nginx/nginx.conf
  18. gzip on;
  19. gzip_min_length 1;
  20. gzip_comp_level 2;
  21. gzip_types text/plain applicaiton/x-javascript text/css application/xml text/javascript applicaiton/x-http-php image/jpeg image/gif image/png;
  22. ```
  23. 开放目录和文件
  24. ```
  25. sudo nano /etc/nginx/sites-available/default
  26. server {
  27. listen 5008;
  28. server_name other;
  29. location / {
  30. alias /var/www/publishapplication/d1.xyz/html/;
  31. autoindex on;
  32. index index.html;
  33. try_files $uri $uri/ /index.html;
  34. }
  35. }
  36. ```
  37. 当有并发产生,让`Nginx`控制响应频率。
  38. ```
  39. sudo nano /etc/nginx/sites-available/default
  40. server {
  41. listen 5008;
  42. server_name other;
  43. location / {
  44. alias /var/www/publishapplication/d1.xyz/html/;
  45. autoindex on;
  46. index index.html;
  47. set $limit_rate 1k;
  48. try_files $uri $uri/ /index.html;
  49. }
  50. }
  51. ```
  52. 记录日志
  53. ```
  54. 查看配置:sudo nano /etc/nginx/nginx.conf
  55. 确认日志文件:
  56. access_log /var/log/nginx/access.log;
  57. error_log /var/log/nginx/error.log;
  58. log format main '$remote_addr' --不同域名可以不同日志记录
  59. access_log /var/log/nginx/access.log main;
  60. ```