nginx简单使用 - 图2

下载文件限速

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80; # 端口
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. root html;
  29. index index.html index.htm;
  30. }
  31. location /download{
  32. alias D:/nginx-1.22.0/root; # 文件存储地址
  33. #limit_rate 512k;
  34. sendfile on;
  35. autoindex on; # 开启目录文件列表
  36. autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes
  37. autoindex_localtime on; # 显示的文件时间为文件的服务器时间
  38. charset gbk; # 避免中文乱码
  39. }
  40. #error_page 404 /404.html;
  41. # redirect server error pages to the static page /50x.html
  42. #
  43. error_page 500 502 503 504 /50x.html;
  44. location = /50x.html {
  45. root html;
  46. }
  47. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  48. #
  49. #location ~ \.php$ {
  50. # proxy_pass http://127.0.0.1;
  51. #}
  52. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  53. #
  54. #location ~ \.php$ {
  55. # root html;
  56. # fastcgi_pass 127.0.0.1:9000;
  57. # fastcgi_index index.php;
  58. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  59. # include fastcgi_params;
  60. #}
  61. # deny access to .htaccess files, if Apache's document root
  62. # concurs with nginx's one
  63. #
  64. #location ~ /\.ht {
  65. # deny all;
  66. #}
  67. }
  68. # another virtual host using mix of IP-, name-, and port-based configuration
  69. #
  70. #server {
  71. # listen 8000;
  72. # listen somename:8080;
  73. # server_name somename alias another.alias;
  74. # location / {
  75. # root html;
  76. # index index.html index.htm;
  77. # }
  78. #}
  79. # HTTPS server
  80. #
  81. #server {
  82. # listen 443 ssl;
  83. # server_name localhost;
  84. # ssl_certificate cert.pem;
  85. # ssl_certificate_key cert.key;
  86. # ssl_session_cache shared:SSL:1m;
  87. # ssl_session_timeout 5m;
  88. # ssl_ciphers HIGH:!aNULL:!MD5;
  89. # ssl_prefer_server_ciphers on;
  90. # location / {
  91. # root html;
  92. # index index.html index.htm;
  93. # }
  94. #}
  95. }

反向代理

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. root html;
  29. index index.html index.htm;
  30. }
  31. }
  32. server {
  33. listen 8089;
  34. server_name localhost;
  35. location / {
  36. # add_header Access-Control-Allow-Origin http://localhost:3000 always;
  37. # add_header Access-Control-Allow-Origin *;
  38. # add_header Access-Control-Allow-Headers "Accept,Accept-Encoding,Accept-Language,Connection,Content-Length,Content-Type,Host,Origin,Referer,User-Agent";
  39. # add_header Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS";
  40. # add_header Access-Control-Allow-Credentials true;
  41. add_header 'Access-Control-Allow-Headers' '*';
  42. add_header 'Access-Control-Allow-Methods' '*';
  43. add_header 'Access-Control-Allow-Credentials' 'true';
  44. add_header 'Access-Control-Allow-Origin' '*';
  45. if ($request_method = 'OPTIONS') {
  46. return 200;
  47. }
  48. proxy_cookie_domain ~\.?baidu.com $host;
  49. proxy_pass http://baidu.com;
  50. }
  51. }
  52. }

常用脚本

stop.bat
version.bat
doc.bat
force_stop.bat
open.bat
reload.bat
start.bat