• 企业架构LNMP学习笔记11


    Nginx配置文件的介绍:

    1. #nginx子进程启动用户
    2. #user nobody;
    3. #子进程数量 一般调整为cpu核数或者倍数
    4. worker_processes 1;
    5. #错误日志定义
    6. #error_log logs/error.log;
    7. #error_log logs/error.log notice;
    8. #error_log logs/error.log info;
    9. #进程pid 存储文件
    10. #pid logs/nginx.pid;
    11. #事件
    12. events {
    13. #每个子进程的连接数 nginx当前并发量 worker_processes * worker_connections
    14. worker_connections 1024;
    15. }
    16. #http协议段
    17. http {
    18. #引入 文件扩展名和与文件类型映射表
    19. include mime.types;
    20. #默认文件类型
    21. default_type application/octet-stream;
    22. #访问日志access.log的格式
    23. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    24. # '$status $body_bytes_sent "$http_referer" '
    25. # '"$http_user_agent" "$http_x_forwarded_for"';
    26. #访问日志存储路径
    27. #access_log logs/access.log main;
    28. #linux内核 提供文件读写的机制
    29. sendfile on;
    30. #tcp_nopush on;
    31. #keepalive_timeout 0;
    32. #长连接超时时间 单位为s
    33. keepalive_timeout 65;
    34. #gzip压缩
    35. #gzip on;
    36. #server虚拟主机的配置
    37. server {
    38. #监听端口
    39. listen 80;
    40. #域名 可以有多个 用空格分隔
    41. server_name localhost;
    42. #默认编码
    43. #charset koi8-r;
    44. #access_log logs/host.access.log main;
    45. #location 用来匹配url
    46. location / {
    47. #默认访问的网站路径
    48. root html;
    49. #默认访问页面 从前往后的顺序查找
    50. index index.html index.htm;
    51. }
    52. #error_page 404 /404.html;
    53. # redirect server error pages to the static page /50x.html
    54. #
    55. error_page 500 502 503 504 /50x.html;
    56. location = /50x.html {
    57. root html;
    58. }
    59. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    60. #
    61. #location ~ \.php$ {
    62. # proxy_pass http://127.0.0.1;
    63. #}
    64. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    65. #
    66. #location ~ \.php$ {
    67. # root html;
    68. # fastcgi_pass 127.0.0.1:9000;
    69. # fastcgi_index index.php;
    70. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    71. # include fastcgi_params;
    72. #}
    73. # deny access to .htaccess files, if Apache's document root
    74. # concurs with nginx's one
    75. #
    76. #location ~ /\.ht {
    77. # deny all;
    78. #}
    79. }
    80. # another virtual host using mix of IP-, name-, and port-based configuration
    81. #
    82. #server {
    83. # listen 8000;
    84. # listen somename:8080;
    85. # server_name somename alias another.alias;
    86. # location / {
    87. # root html;
    88. # index index.html index.htm;
    89. # }
    90. #}
    91. # HTTPS server
    92. #
    93. #server {
    94. # listen 443 ssl;
    95. # server_name localhost;
    96. # ssl_certificate cert.pem;
    97. # ssl_certificate_key cert.key;
    98. # ssl_session_cache shared:SSL:1m;
    99. # ssl_session_timeout 5m;
    100. # ssl_ciphers HIGH:!aNULL:!MD5;
    101. # ssl_prefer_server_ciphers on;
    102. # location / {
    103. # root html;
    104. # index index.html index.htm;
    105. # }
    106. #}
    107. }

    worker_processes 1:

    子进程数量  一般调整为cpu核心数或者倍数。CPU同时只能做一个事情。CPU上下文切换。

    在这个地方,我还排除了一个错误。找不到/usr/local/nginx/log/nginx.pid文件了。然后我通过kill -TERM PID命令,然后再启动nginx进程。

    #事件
    events {
        #每个子进程的连接数         nginx当前并发量  worker_processes * worker_connections
        worker_connections  1024;
    }

    说明:并发量的概念。并发量是多少?

    include       mime.types;
    超文本所支持的格式。

    sendfile on;

    是nginx内核加件读写IO的机制。默认是开启的。

        #keepalive_timeout  0;
        keepalive_timeout  65;
    说明:长连接超时时间,单位为秒。当客户端与服务器端断开超过65秒,那么连接就断开了。

    回收资源。0 不会设置超时时间。

    Server段:

    Server虚拟主机的配置。

    server_name:域名,可以有多个,用空格分隔。

    location用来匹配URL:

    root html;

    默认访问的网站路径。

    index index.html index.htm

    默认访问页面,从前往后的顺序查找。

    例子:index index.php index.html index.htm

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    这是一段代理。以.php文件结尾的,代理到本机的80端口。

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
            #    root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    把PHP脚本发送给以php启动的FastCGI服务器php-fpm 9000端口。

    注意:

    http=>==server===>location 递进关系

    我们经常配置的是server端。

  • 相关阅读:
    27.基于ADS的不等分威尔金森功分器设计
    kafka-生产者事务-数据传递语义&事务介绍&事务消息发送
    26 docker前后端部署
    C++ Reference: Standard C++ Library reference: C Library: cwchar: putwchar
    强化学习从基础到进阶-案例与实践[6]:演员-评论员算法(advantage actor-critic,A2C),异步A2C、与生成对抗网络的联系等详解
    【科技素养】蓝桥杯STEMA 科技素养组模拟练习试卷A
    大数据Kubernetes(K8S)命令指南 超级详细!
    [运维]如何快速压缩一个数据库的硬盘占用大小(简单粗暴但有效)
    1923. 最长公共子路径
    [机器学习] 通俗理解机器学习分类模型评估指标-准确率、精准率、召回率
  • 原文地址:https://blog.csdn.net/chang_chunhua/article/details/132653882