鼎鼎知识库
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

10反向代理服务.md 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 说到反向代理,肯定是有上游服务。
  2. 配置一个静态网站。
  3. ```
  4. 确定配置文件:sudo nano /etc/nginx/sites-available/default
  5. server {
  6. listen 127.0.0.1:5008; //也就是只针对本机开放
  7. server_name other;
  8. location / {
  9. alias /var/www/publishapplication/d1.xyz/html/;
  10. autoindex on;
  11. index index.html;
  12. set $limit_rate 1k;
  13. try_files $uri $uri/ /index.html;
  14. }
  15. }
  16. 把原先的进程停掉: nginx -s stop
  17. 重新打开:nginx
  18. ```
  19. 设置反向代理
  20. ```
  21. 配置文件:sudo nano /etc/nginx/sites-available/default
  22. upstream local {
  23. server 127.0.0.1:5008;
  24. }
  25. server {
  26. listen 80;
  27. server_name demo.com *.demo.com;
  28. location / {
  29. #root /var/www/html;
  30. #index index.html;
  31. #try_files $uri $uri/ /index.html;
  32. proxy_set_header Host $host;
  33. proxy_set_header X-Real-IP $remote_addr;//告诉上游服务器,从远端与Nginx的TCP连接中获取
  34. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  35. proxy_pass http://local;
  36. }
  37. }
  38. server {
  39. listen 127.0.0.1:5008;
  40. server_name other;
  41. location / {
  42. alias /var/www/publishapplication/d1.xyz/html/;
  43. autoindex on;
  44. index index.html;
  45. set $limit_rate 1k;
  46. try_files $uri $uri/ /index.html;
  47. }
  48. }
  49. ```
  50. 设置缓存。也就是把上游服务器的内容先缓存起来一段时间。
  51. ```
  52. 配置文件:sudo nano /etc/nginx/nginx.conf
  53. http {
  54. //10m的共享内存
  55. //名称是my_cache
  56. proxy_cache_path /tmp/nginxcache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;
  57. }
  58. 配置文件:sudo nano /etc/nginx/sites-available/default
  59. upstream local {
  60. server 127.0.0.1:5008;
  61. }
  62. server {
  63. listen 80;
  64. server_name _;
  65. location / {
  66. proxy_set_header Host $host;
  67. proxy_set_header X-Real-IP $remote_addr;
  68. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  69. proxy_cache my_cache;
  70. proxy_cache_key #host$uri$is_args$args;
  71. proxy_cache_valid 200 304 303 ld;
  72. proxy_pass http://local;
  73. }
  74. }
  75. ```