Nginx是什么?
    Nginx (engine x) 是一个高性能的HTTP反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。
    Nginx配置文件

    1. #user nobody;
    2. worker_processes 1; #worker进程的数量
    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; #每个worker进程支持最大的连接数量
    9. }
    10. http { #http区块
    11. include mime.types; #Nginx支持的媒体库文件
    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. #监听端口
    23. upstream AspNetCore31{ #上游服务器设置,主要为反向代理、负载均衡相关配置
    24. server localhost:5726;
    25. server localhost:5727;
    26. server localhost:5728;
    27. }
    28. server { #第一个server区块,表示一个独立的虚拟主机站点
    29. listen 8080; #Nginx监听端口
    30. server_name localhost; #服务器名称或域名
    31. #charset koi8-r;
    32. #access_log logs/host.access.log main;
    33. location / {
    34. proxy_pass http://AspNetCore31;
    35. }
    36. #error_page 404 /404.html;
    37. # redirect server error pages to the static page /50x.html
    38. #
    39. error_page 500 502 503 504 /50x.html;
    40. location = /50x.html {
    41. root html;
    42. }
    43. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    44. #
    45. #location ~ \.php$ {
    46. # proxy_pass http://127.0.0.1;
    47. #}
    48. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    49. #
    50. #location ~ \.php$ {
    51. # root html;
    52. # fastcgi_pass 127.0.0.1:9000;
    53. # fastcgi_index index.php;
    54. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    55. # include fastcgi_params;
    56. #}
    57. # deny access to .htaccess files, if Apache's document root
    58. # concurs with nginx's one
    59. #
    60. #location ~ /\.ht {
    61. # deny all;
    62. #}
    63. }
    64. # another virtual host using mix of IP-, name-, and port-based configuration
    65. #
    66. #server {
    67. # listen 8000;
    68. # listen somename:8080;
    69. # server_name somename alias another.alias;
    70. # location / {
    71. # root html;
    72. # index index.html index.htm;
    73. # }
    74. #}
    75. # HTTPS server
    76. #
    77. #server {
    78. # listen 443 ssl;
    79. # server_name localhost;
    80. # ssl_certificate cert.pem;
    81. # ssl_certificate_key cert.key;
    82. # ssl_session_cache shared:SSL:1m;
    83. # ssl_session_timeout 5m;
    84. # ssl_ciphers HIGH:!aNULL:!MD5;
    85. # ssl_prefer_server_ciphers on;
    86. # location / {
    87. # root html;
    88. # index index.html index.htm;
    89. # }
    90. #}

    }
    Nginx负载均衡策略
    1、轮询策略
    2、权重策略
    3、Ip_Hash策略
    4、Url_Hash策略