{"id":905,"date":"2022-09-05T21:37:22","date_gmt":"2022-09-05T13:37:22","guid":{"rendered":"https:\/\/www.dd-home.top\/?p=905"},"modified":"2022-09-07T15:28:59","modified_gmt":"2022-09-07T07:28:59","slug":"nginx%e7%9a%84%e5%9f%ba%e6%9c%ac%e9%85%8d%e7%bd%ae%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=905","title":{"rendered":"Nginx\u7684\u57fa\u672c\u914d\u7f6e\u4fe1\u606f"},"content":{"rendered":"<p><!--more--><\/p>\n<h4>1\u3001\u67e5\u770b\u5f53\u524dcentos\u7684cpu \u4fe1\u606f\u53ca\u5185\u5b58\u4fe1\u606f<\/h4>\n<pre><code class=\"language-shell\"># \u603b\u6838\u6570 = \u7269\u7406CPU\u4e2a\u6570 X \u6bcf\u9897\u7269\u7406CPU\u7684\u6838\u6570 \r\n# \u603b\u903b\u8f91CPU\u6570 = \u7269\u7406CPU\u4e2a\u6570 X \u6bcf\u9897\u7269\u7406CPU\u7684\u6838\u6570 X \u8d85\u7ebf\u7a0b\u6570\r\n# \u67e5\u770bCPU \u4fe1\u606f\r\ncat \/proc\/cpuinfo |grep \"name\" |cut -f2 -d: |uniq -c\r\n\r\n# \u67e5\u770bCPU \u6838\u5fc3\u4fe1\u606f\r\ncat \/proc\/cpuinfo | grep \"physical\"| sort |uniq -c\r\n\r\ngetconf LONG_BIT\r\n\r\ncat \/proc\/cpuinfo\r\n<\/code><\/pre>\n<h4>2\u3001nginx CPU\u4f18\u5316<\/h4>\n<pre><code class=\"language-nginx\"># \u56db\u6838worker\u914d\u7f6e\r\nworker_processes  4;\r\nworker_cpu_affinity 0001 0010 0100 1000;\r\n\r\n# \u516b\u6838worker\u914d\u7f6e\r\nworker_processes 8;\r\nworker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 1000000;\r\n\r\nworker_rlimit_nofile 65535;\r\n\r\nevents {\r\n    use epoll;\r\n    worker_connections 65535;\r\n    multi_accept on;\r\n}<\/code><\/pre>\n<pre><code class=\"language-nginx\">\r\n#user  nobody;\r\n# \r\nworker_processes  1;\r\n\r\n# \u56db\u6838worker\u914d\u7f6e\r\n# worker_processes  4;\r\n# worker_cpu_affinity 0001 0010 0100 1000;\r\n\r\n# \u516b\u6838worker\u914d\u7f6e\r\n# worker_processes 8;\r\n# worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 1000000;\r\n\r\n#error_log  logs\/error.log;\r\n#error_log  logs\/error.log  notice;\r\n#error_log  logs\/error.log  info;\r\n#error_log  \"pipe:rollback logs\/error_log interval=1d baknum=7 maxsize=2G\";\r\n\r\n#pid        logs\/nginx.pid;\r\n\r\nworker_rlimit_nofile 65535;\r\nevents {\r\n    use epoll;\r\n    worker_connections 65535;\r\n    multi_accept on;\r\n}\r\n\r\nhttp {\r\n    # \u9690\u85cf\u7248\u672c\u53f7\r\n    server_tokens off;\r\n    include       mime.types;\r\n    default_type  application\/octet-stream;\r\n    map $http_upgrade $connection_upgrade {\r\n        default upgrade;\r\n        ''   close;\r\n    }\r\n\r\n    #log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\r\n    #                  '$status $body_bytes_sent \"$http_referer\" '\r\n    #                  '\"$http_user_agent\" \"$http_x_forwarded_for\"';\r\n\r\n    #access_log  logs\/access.log  main;\r\n    #access_log  \"pipe:rollback logs\/access_log interval=1d baknum=7 maxsize=2G\"  main;\r\n\r\n    sendfile        on;\r\n    #tcp_nopush     on;\r\n\r\n    #keepalive_timeout  0;\r\n    keepalive_timeout  65;\r\n\r\n    #gzip  on;\r\n\r\n    # X-Frame-Options \u9632frame\u5d4c\u5165\r\n    add_header X-Frame-Options SAMEORIGIN;\r\n    # X-XSS-Protection\r\n    add_header X-Xss-Protection \"1; mode=block\";\r\n    # \u7981\u7528\u4e86\u5ba2\u6237\u7aef\u7684 MIME \u7c7b\u578b\u55c5\u63a2\u884c\u4e3a\r\n    add_header X-Content-Type-Options nosniff;\r\n\r\n    server {\r\n        listen       80;\r\n        server_name  localhost;\r\n\r\n        #charset koi8-r;\r\n\r\n        #access_log  logs\/host.access.log  main;\r\n        #access_log  \"pipe:rollback logs\/host.access_log interval=1d baknum=7 maxsize=2G\"  main;\r\n\r\n        location \/ {\r\n            root   html;\r\n            index  index.html index.htm;\r\n        }\r\n\r\n        #error_page  404              \/404.html;\r\n\r\n        # redirect server error pages to the static page \/50x.html\r\n        #\r\n        error_page   500 502 503 504  \/50x.html;\r\n        location = \/50x.html {\r\n            root   html;\r\n        }\r\n\r\n        # proxy the PHP scripts to Apache listening on 127.0.0.1:80\r\n        #\r\n        #location ~ \\.php$ {\r\n        #    proxy_pass   http:\/\/127.0.0.1;\r\n        #}\r\n\r\n        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\r\n        #\r\n        #location ~ \\.php$ {\r\n        #    root           html;\r\n        #    fastcgi_pass   127.0.0.1:9000;\r\n        #    fastcgi_index  index.php;\r\n        #    fastcgi_param  SCRIPT_FILENAME  \/scripts$fastcgi_script_name;\r\n        #    include        fastcgi_params;\r\n        #}\r\n\r\n        # pass the Dubbo rpc to Dubbo provider server listening on 127.0.0.1:20880\r\n        #\r\n        #location \/dubbo {\r\n        #    dubbo_pass_all_headers on;\r\n        #    dubbo_pass_set args $args;\r\n        #    dubbo_pass_set uri $uri;\r\n        #    dubbo_pass_set method $request_method;\r\n        #\r\n        #    dubbo_pass org.apache.dubbo.samples.tengine.DemoService 0.0.0 tengineDubbo dubbo_backend;\r\n        #}\r\n\r\n        # deny access to .htaccess files, if Apache's document root\r\n        # concurs with nginx's one\r\n        #\r\n        #location ~ \/\\.ht {\r\n        #    deny  all;\r\n        #}\r\n    }\r\n\r\n    #server {\r\n        #listen 443 ssl;\r\n        #charset utf-8;\r\n        #\u914d\u7f6eHTTPS\u7684\u9ed8\u8ba4\u8bbf\u95ee\u7aef\u53e3\u4e3a443\u3002\r\n        #\u5982\u679c\u672a\u5728\u6b64\u5904\u914d\u7f6eHTTPS\u7684\u9ed8\u8ba4\u8bbf\u95ee\u7aef\u53e3\uff0c\u53ef\u80fd\u4f1a\u9020\u6210Nginx\u65e0\u6cd5\u542f\u52a8\u3002\r\n        #\u5982\u679c\u60a8\u4f7f\u7528Nginx 1.15.0\u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u8bf7\u4f7f\u7528listen 443 ssl\u4ee3\u66fflisten 443\u548cssl on\u3002\r\n        #server_name xxxxxx.xxx.xxx; #\u9700\u8981\u5c06yourdomain.com\u66ff\u6362\u6210\u8bc1\u4e66\u7ed1\u5b9a\u7684\u57df\u540d\u3002\r\n        #add_header Strict-Transport-Security \"max-age=63072000; includeSubdomains\" always;\r\n        #ssl_certificate cert\/xxx.pem;  #\u9700\u8981\u5c06cert-file-name.pem\u66ff\u6362\u6210\u5df2\u4e0a\u4f20\u7684\u8bc1\u4e66\u6587\u4ef6\u7684\u540d\u79f0\u3002\r\n        #ssl_certificate_key cert\/xxx.key; #\u9700\u8981\u5c06cert-file-name.key\u66ff\u6362\u6210\u5df2\u4e0a\u4f20\u7684\u8bc1\u4e66\u5bc6\u94a5\u6587\u4ef6\u7684\u540d\u79f0\u3002\r\n        #ssl_session_timeout 5m;\r\n        #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;\r\n        #\u8868\u793a\u4f7f\u7528\u7684\u52a0\u5bc6\u5957\u4ef6\u7684\u7c7b\u578b\u3002\r\n        #ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #\u8868\u793a\u4f7f\u7528\u7684TLS\u534f\u8bae\u7684\u7c7b\u578b\u3002\r\n        #ssl_prefer_server_ciphers on;\r\n        #location \/a\/ {\r\n            #proxy_pass https:\/\/xxx.xxx.xxx.xxx:443\/a\/;\r\n            #proxy_set_header Host                $host:$server_port;\r\n            #proxy_set_header X-Forwarded-For     $proxy_add_x_forwarded_for;\r\n            #proxy_set_header X-Forwarded-Proto   $scheme;\r\n            #proxy_set_header X-Forwarded-Port    $server_port;\r\n        #}\r\n\r\n        #location \/ {\r\n           #proxy_pass https:\/\/xxx.xxx.xxx.xxx:443\/;\r\n           #proxy_set_header Host $http_host;\r\n           #proxy_read_timeout 60s;\r\n           #proxy_set_header X-Real_IP $remote_addr;\r\n            #proxy_set_header X-Forwarded-for $remote_addr;\r\n            #proxy_http_version 1.1;\r\n            #proxy_set_header Upgrade $http_upgrade;\r\n            #proxy_set_header Connection 'Upgrade';\r\n        #}\r\n        #error_page   404 403  \/40x.html;\r\n        #location = \/40x.html {\r\n            #root   html;\r\n        #}\r\n    #}\r\n\r\n    # upstream for Dubbo rpc to Dubbo provider server listening on 127.0.0.1:20880\r\n    #\r\n    #upstream dubbo_backend {\r\n    #    multi 1;\r\n    #    server 127.0.0.1:20880;\r\n    #}\r\n\r\n    # another virtual host using mix of IP-, name-, and port-based configuration\r\n    #\r\n    #server {\r\n    #    listen       8000;\r\n    #    listen       somename:8080;\r\n    #    server_name  somename  alias  another.alias;\r\n\r\n    #    location \/ {\r\n    #        root   html;\r\n    #        index  index.html index.htm;\r\n    #    }\r\n    #}\r\n\r\n    # HTTPS server\r\n    #\r\n    #server {\r\n    #    listen       443 ssl;\r\n    #    server_name  localhost;\r\n\r\n    #    add_header Strict-Transport-Security \"max-age=63072000; includeSubdomains\" always;\r\n\r\n    #    ssl_certificate      cert.pem;\r\n    #    ssl_certificate_key  cert.key;\r\n\r\n    #    ssl_session_cache    shared:SSL:1m;\r\n    #    ssl_session_timeout  5m;\r\n\r\n    #    ssl_ciphers  HIGH:!aNULL:!MD5;\r\n    #    ssl_prefer_server_ciphers  on;\r\n\r\n    #    location \/ {\r\n    #        root   html;\r\n    #        index  index.html index.htm;\r\n    #    }\r\n    #}\r\n\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-905","post","type-post","status-publish","format-standard","hentry","category-5","category-6"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=905"}],"version-history":[{"count":3,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/905\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/905\/revisions\/926"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}