找到ngxin的安装位置在里面有个conf文件夹,里面有一个ngxin.conf文件
    Nginx配置文件里面有三个核心部分:

    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. 这里是全局配置,可以指定用户,可以指定进程等信息
    1. events {
    2. worker_connections 1024;
    3. }
    4. 可以指定线程数量,可以监听事件 比如说现在是1024个进程
    1. http {
    2. http里面还可以配置一些负载均衡
    3. include mime.types;
    4. default_type application/octet-stream;
    5. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    6. # '$status $body_bytes_sent "$http_referer" '
    7. # '"$http_user_agent" "$http_x_forwarded_for"';
    8. #access_log logs/access.log main;
    9. sendfile on;
    10. #tcp_nopush on;
    11. #keepalive_timeout 0;
    12. keepalive_timeout 65;
    13. #gzip on; 这里这一部分是http的配置就是请求的
    14. --------------------------------------------------------------------
    15. upstream kuangsheng{
    16. 这里配置的是负载均衡
    17. 配置服务器的资源
    18. }
    19. server{
    20. listen 9001;
    21. server_name localhost;
    22. location / {
    23. 这里是代理 代理9001端口
    24. root F:/cloud_ma/hm-mall-admin;
    25. }
    26. }
    27. server{
    28. listen 9002;
    29. server_name localhost;
    30. location / {
    31. root F:/cloud_ma/hm-mall-portal;
    32. }
    33. }
    34. server {
    35. listen 80;
    36. server_name localhost;
    37. #charset koi8-r;
    38. #access_log logs/host.access.log main;
    39. location / {
    40. root html;
    41. index index.html index.htm;
    42. }
    43. #error_page 404 /404.html;
    44. # redirect server error pages to the static page /50x.html
    45. #
    46. error_page 500 502 503 504 /50x.html;
    47. location = /50x.html {
    48. root html;
    49. }
    50. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    51. #
    52. #location ~ \.php$ {
    53. # proxy_pass http://127.0.0.1;
    54. #}
    55. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    56. #
    57. #location ~ \.php$ {
    58. # root html;
    59. # fastcgi_pass 127.0.0.1:9000;
    60. # fastcgi_index index.php;
    61. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    62. # include fastcgi_params;
    63. #}
    64. # deny access to .htaccess files, if Apache's document root
    65. # concurs with nginx's one
    66. #
    67. #location ~ /\.ht {
    68. # deny all;
    69. #}
    70. }
    71. # another virtual host using mix of IP-, name-, and port-based configuration
    72. #
    73. #server {
    74. # listen 8000;
    75. # listen somename:8080;
    76. # server_name somename alias another.alias;
    77. # location / {
    78. # root html;
    79. # index index.html index.htm;
    80. # }
    81. #}
    82. # HTTPS server
    83. #
    84. #server {
    85. # listen 443 ssl;
    86. # server_name localhost;
    87. # ssl_certificate cert.pem;
    88. # ssl_certificate_key cert.key;
    89. # ssl_session_cache shared:SSL:1m;
    90. # ssl_session_timeout 5m;
    91. # ssl_ciphers HIGH:!aNULL:!MD5;
    92. # ssl_prefer_server_ciphers on;
    93. # location / {
    94. # root html;
    95. # index index.html index.htm;
    96. # }
    97. #}
    98. }

    image.png
    weight这里是权重
    image.png
    用户是无感知的喔

    Nginx前端项目集成:静态服务器搭建:动静分离
    image.png
    反向代理去访问动态的数据
    把前端项目放在一个工作目录下,比如跟你的项目代码放在
    一起但是他们是同级别的文件夹
    需要去配置当前的nginx.conf文件
    去配置:
    反向代理的配置
    静态资源的配置
    步骤:
    我们需要在conf文件夹下面去创建前端项目文件夹
    比如我说leadnews.conf
    image.png

    需要在这个文件夹里面去创建前端项目名.conf文件

    image.png

    image.png
    如果想要此配置生效那么我们就要去nginx.conf文件里面
    去做引入

    image.png

    这个时候其实就可以去访问网关的位置,然后他就回去
    路由我的其他的服务了
    这个就是动静分离