{"id":327,"date":"2023-08-21T14:03:17","date_gmt":"2023-08-21T06:03:17","guid":{"rendered":"http:\/\/124.220.91.76\/?p=327"},"modified":"2023-08-22T10:11:10","modified_gmt":"2023-08-22T02:11:10","slug":"linux%e4%b9%8b-nginx-conf-%e8%a7%a3%e6%9e%90%e7%89%88%e3%80%81%e5%8e%9f%e7%89%88%e3%80%81%e9%a1%b9%e7%9b%ae%e4%bd%bf%e7%94%a8%e7%89%88%ef%bc%88%e5%ae%98%e6%96%b9%e6%96%87%e6%a1%a3%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.9youx.com\/?p=327","title":{"rendered":"linux\u4e4b nginx.conf \u89e3\u6790\u7248\u3001\u539f\u7248\u3001\u9879\u76ee\u4f7f\u7528\u7248\uff08\u5b98\u65b9\u6587\u6863\uff09"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f80101\" class=\"has-inline-color\">\u4e00\u3001\u89e3\u6790\u7248<\/mark><\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">## nginx\u8fdb\u7a0b\u6570\uff0c\u5efa\u8bae\u8bbe\u7f6e\u4e3a\u7b49\u4e8eCPU\u603b\u6838\u5fc3\u6570\u3002\nworker_processes  1;\n## \u4e8b\u4ef6\u533a\u5757\u5f00\u59cb\nevents {\n## \u5355\u4e2a\u8fdb\u7a0b\u6700\u5927\u8fde\u63a5\u6570\uff08\u6700\u5927\u8fde\u63a5\u6570=\u8fde\u63a5\u6570*\u8fdb\u7a0b\u6570\uff09\n## \u6839\u636e\u786c\u4ef6\u8c03\u6574\uff0c\u548c\u524d\u9762\u5de5\u4f5c\u8fdb\u7a0b\u914d\u5408\u8d77\u6765\u7528\uff0c\u5c3d\u91cf\u5927\uff0c\u4f46\u662f\u522b\u628acpu\u8dd1\u5230100%\u5c31\u884c\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u5141\u8bb8\u7684\u6700\u591a\u8fde\u63a5\u6570\uff0c\u7406\u8bba\u4e0a\u6bcf\u53f0nginx\u670d\u52a1\u5668\u7684\u6700\u5927\u8fde\u63a5\u6570\u4e3a\u3002\n    worker_connections  1024;\n}\n## \u8bbe\u5b9ahttp\u670d\u52a1\u5668\uff0c\u5229\u7528\u5b83\u7684\u53cd\u5411\u4ee3\u7406\u529f\u80fd\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u652f\u6301\nhttp {\n## include\uff1a\u5bfc\u5165\u5916\u90e8\u6587\u4ef6mime.types\uff0c\u5c06\u6240\u6709types\u63d0\u53d6\u4e3a\u6587\u4ef6\uff0c\u7136\u540e\u5bfc\u5165\u5230nginx\u914d\u7f6e\u6587\u4ef6\u4e2d\n    include       mime.types;\n## \u9ed8\u8ba4\u6587\u4ef6\u7c7b\u578b\n    default_type  application\/octet-stream;\n## \u5f00\u542f\u9ad8\u6548\u6587\u4ef6\u4f20\u8f93\u6a21\u5f0f\uff0csendfile\u6307\u4ee4\u6307\u5b9anginx\u662f\u5426\u8c03\u7528sendfile\u51fd\u6570\u6765\u8f93\u51fa\u6587\u4ef6\uff0c\u5bf9\u4e8e\u666e\u901a\u5e94\u7528\u8bbe\u4e3a on\uff0c\u5982\u679c\u7528\u6765\u8fdb\u884c\u4e0b\u8f7d\u7b49\u5e94\u7528\u78c1\u76d8IO\u91cd\u8d1f\u8f7d\u5e94\u7528\uff0c\u53ef\u8bbe\u7f6e\u4e3aoff\uff0c\u4ee5\u5e73\u8861\u78c1\u76d8\u4e0e\u7f51\u7edcI\/O\u5904\u7406\u901f\u5ea6\uff0c\u964d\u4f4e\u7cfb\u7edf\u7684\u8d1f\u8f7d\u3002\u6ce8\u610f\uff1a\u5982\u679c\u56fe\u7247\u663e\u793a\u4e0d\u6b63\u5e38\u628a\u8fd9\u4e2a\u6539\u6210off\u3002\n## sendfile\u6307\u4ee4\u6307\u5b9a nginx \u662f\u5426\u8c03\u7528sendfile \u51fd\u6570\uff08zero copy \u65b9\u5f0f\uff09\u6765\u8f93\u51fa\u6587\u4ef6\uff0c\u5bf9\u4e8e\u666e\u901a\u5e94\u7528\uff0c\u5fc5\u987b\u8bbe\u4e3aon\u3002\u5982\u679c\u7528\u6765\u8fdb\u884c\u4e0b\u8f7d\u7b49\u5e94\u7528\u78c1\u76d8IO\u91cd\u8d1f\u8f7d\u5e94\u7528\uff0c\u53ef\u8bbe\u7f6e\u4e3aoff\uff0c\u4ee5\u5e73\u8861\u78c1\u76d8\u4e0e\u7f51\u7edcIO\u5904\u7406\u901f\u5ea6\uff0c\u964d\u4f4e\u7cfb\u7edfuptime\u3002\n    sendfile        on;\n## \u957f\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u662f\u79d2\n    keepalive_timeout  65;\n## \u7b2c\u4e00\u4e2aServer\u533a\u5757\u5f00\u59cb\uff0c\u8868\u793a\u4e00\u4e2a\u72ec\u7acb\u7684\u865a\u62df\u4e3b\u673a\u7ad9\u70b9\n    gzip on; # \u9ed8\u8ba4off\uff0c\u662f\u5426\u5f00\u542fgzip\n    gzip_types text\/plain text\/css application\/json application\/x-javascript text\/xml application\/xml application\/xml+rss text\/javascript;\n\n## \u4e0a\u9762\u4e24\u4e2a\u5f00\u542f\u57fa\u672c\u5c31\u80fd\u8dd1\u8d77\u4e86\uff0c\u4e0b\u9762\u7684\u613f\u610f\u6298\u817e\u5c31\u4e86\u89e3\u4e00\u4e0b\n    gzip_static on;\n    gzip_proxied any;\n    gzip_vary on;\n    gzip_comp_level 6;\n    gzip_buffers 16 8k;\n    # gzip_min_length 1k;\n    gzip_http_version 1.1;\n# \u7b2c\u4e00\u4e2a\u7f51\u7ad9\uff1a\u4e2a\u4eba\u535a\u5ba2\u9879\u76ee\u914d\u7f6e\n    server {\n\t  \tlisten       8080;\n\t  \troot         \/data\/www\/hexo;\n\t  \tindex        index.html;\n\t  \tlocation \/ {\n\t  \t\ttry_files $uri $uri\/ \/index.html; # \u8def\u7531\u6a21\u5f0fhistory\u7684\u4fee\u6539\n\t  \t}\n    }\n\n## \u7b2c\u4e8c\u4e2a\u7f51\u7ad9\uff1aGeoV\u7f51\u7ad9\u9879\u76ee\u914d\u7f6e\n    server {\n    \tlisten       8081;\n    \troot         \/data\/www\/geov;\n    \tindex        index.html;\n    \tlocation \/ {}\n    }\n## \u7b2c\u4e09\u4e2a\u7f51\u7ad9\uff1a\n    server {\n## \u63d0\u4f9b\u670d\u52a1\u7684\u7aef\u53e3\uff0c\u9ed8\u8ba480\n        listen       80;\n## \u63d0\u4f9b\u670d\u52a1\u7684\u57df\u540d\u4e3b\u673a\u540d\n        server_name  localhost;\n## \u5bf9 \"\/\" \u542f\u7528\u53cd\u5411\u4ee3\u7406,\u7b2c\u4e00\u4e2alocation\u533a\u5757\u5f00\u59cb\n        location \/ {\n            root   html;  #\u670d\u52a1\u9ed8\u8ba4\u542f\u52a8\u76ee\u5f55\n            index  index.html index.htm; # \u9ed8\u8ba4\u7684\u9996\u9875\u6587\u4ef6\uff0c\u591a\u4e2a\u7528\u7a7a\u683c\u5206\u5f00\n        }\n## \u63a5\u53e3\u7aef\n        location \/police\/ {\n            proxy_pass   http:\/\/192.168.1.182:8852\/police\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout   60;\n            proxy_send_timeout      60;\n            proxy_read_timeout      90;\n        }\n## py\u63a5\u53e3\u7aef\n        location \/py\/ {\n            proxy_pass   http:\/\/192.168.1.182:8852\/py\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout   60;\n            proxy_send_timeout      60;\n            proxy_read_timeout      90;\n        }\n## \u9519\u8bef\u9875\u9762\u8def\u7531\n        error_page   500 502 503 504  \/50x.html; # \u51fa\u73b0\u5bf9\u5e94\u7684http\u72b6\u6001\u7801\u65f6\uff0c\u4f7f\u752850x.html\u56de\u5e94\u5ba2\u6237\n        location = \/50x.html { # location\u533a\u5757\u5f00\u59cb\uff0c\u8bbf\u95ee50x.html\n            root   html;  # \u6307\u5b9a\u5bf9\u5e94\u7684\u7ad9\u70b9\u76ee\u5f55\u4e3ahtml\n        }\n    }\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f90505\" class=\"has-inline-color\">\u4e8c\u3001\u539f\u7248<\/mark><\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\n#user  nobody;\nworker_processes  1;\n\n#error_log  logs\/error.log;\n#error_log  logs\/error.log  notice;\n#error_log  logs\/error.log  info;\n\n#pid        logs\/nginx.pid;\n\n\nevents {\n    worker_connections  1024;\n}\n\n\nhttp {\n    include       mime.types;\n    default_type  application\/octet-stream;\n\n    #log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n    #                  '$status $body_bytes_sent \"$http_referer\" '\n    #                  '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    #access_log  logs\/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    #keepalive_timeout  0;\n    keepalive_timeout  65;\n\n    #gzip  on;\n\n    server {\n        listen       80;\n        server_name  localhost;\n\n        #charset koi8-r;\n\n        #access_log  logs\/host.access.log  main;\n\n        location \/ {\n            root   html;\n            index  index.html index.htm;\n        }\n\n        #error_page  404              \/404.html;\n\n        # redirect server error pages to the static page \/50x.html\n        #\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n\n        # proxy the PHP scripts to Apache listening on 127.0.0.1:80\n        #\n        #location ~ \\.php$ {\n        #    proxy_pass   http:\/\/127.0.0.1;\n        #}\n\n        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n        #\n        #location ~ \\.php$ {\n        #    root           html;\n        #    fastcgi_pass   127.0.0.1:9000;\n        #    fastcgi_index  index.php;\n        #    fastcgi_param  SCRIPT_FILENAME  \/scripts$fastcgi_script_name;\n        #    include        fastcgi_params;\n        #}\n\n        # deny access to .htaccess files, if Apache's document root\n        # concurs with nginx's one\n        #\n        #location ~ \/\\.ht {\n        #    deny  all;\n        #}\n    }\n\n\n    # another virtual host using mix of IP-, name-, and port-based configuration\n    #\n    #server {\n    #    listen       8000;\n    #    listen       somename:8080;\n    #    server_name  somename  alias  another.alias;\n\n    #    location \/ {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n\n\n    # HTTPS server\n    #\n    #server {\n    #    listen       443 ssl;\n    #    server_name  localhost;\n\n    #    ssl_certificate      cert.pem;\n    #    ssl_certificate_key  cert.key;\n\n    #    ssl_session_cache    shared:SSL:1m;\n    #    ssl_session_timeout  5m;\n\n    #    ssl_ciphers  HIGH:!aNULL:!MD5;\n    #    ssl_prefer_server_ciphers  on;\n\n    #    location \/ {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f70606\" class=\"has-inline-color\">\u4e09\u3001\u9879\u76ee\u4f7f\u7528\u7248<\/mark><\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">user nginx;\nworker_processes  1;\n\nerror_log  \/var\/log\/nginx\/error.log debug;\npid        \/var\/run\/nginx.pid;\n\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n\n    log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n                      '$status $body_bytes_sent \"$http_referer\" '\n                      '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    access_log  \/var\/log\/nginx\/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    keepalive_timeout  60;\n    \n\n    client_max_body_size 1024m;\n\n    #gzip  on;\n    gzip on;\n    gzip_min_length  1k;\n    gzip_buffers     4 16k;\n    gzip_http_version 1.1;\n    gzip_comp_level 2;\n    gzip_types     text\/plain application\/javascript application\/x-javascript text\/javascript text\/css application\/xml application\/xml+rss;\n    gzip_vary on;\n    gzip_proxied   expired no-cache no-store private auth;\n    gzip_disable   \"MSIE [1-6]\\.\";\n\n\n    server {\n        listen       80;\n        server_name  127.0.0.1;\n\n\t      #\u6dfb\u52a0\u5934\u90e8\u4fe1\u606f    \n        proxy_set_header Cookie $http_cookie;\n        proxy_set_header X-Forwarded-Host $host;\n        proxy_set_header X-Forwarded-Server $host;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        #charset koi8-r;\n        #access_log  logs\/host.access.log  main;\n\n        location \/ {\n                 #vue\u9879\u76ee\u90e8\u7f72\u8def\u5f84\uff0c\u524d\u7aef\n                 root \/opt\/nginx\/dist;\n                 #\u89e3\u51b3\u9875\u9762\u5237\u65b0404\u95ee\u9898\n                 try_files $uri $uri\/ \/index.html last;\n                 index  index.html index.htm;\n                 add_header Cache-Control \"no-cache, no-store\";\n        }\n        # java\u63a5\u53e3\u7aef\n        location \/police\/ {\n            proxy_pass   http:\/\/suntang-cdh4:8080\/police\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout   60;\n            proxy_send_timeout      60;\n            proxy_read_timeout      90;\n        }\n\n        location \/image\/ {\n            root \/var\/filecenter\/;\n        }\n\n        location \/static\/ {\n            root \/var\/filecenter\/;\n        }\n\n         # py\u63a5\u53e3\u7aef\n        location \/py\/ {\n            proxy_pass   http:\/\/suntang-cdh3:22222\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout   60;\n            proxy_send_timeout      60;\n            proxy_read_timeout      90;\n        }\n\n        # \u5730\u56feapi\n        location \/geoserver\/ {\n            proxy_pass   http:\/\/suntang-cdh4:8060\/geoserver\/;\n            proxy_redirect default;\n        }\n        \n        \n        # warning\n        location \/police\/warning\/ws {\n            proxy_pass   http:\/\/suntang-cdh4:9999\/police\/warning\/ws;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            # websocket\u534f\u8bae\u5347\u7ea7\n            proxy_set_header Upgrade $http_upgrade;\n            proxy_set_header Connection \"upgrade\";\n            # proxy_read_timeout 1800s;\n            # proxy_connect_timeout 4s; #\u914d\u7f6e\u70b91\n            proxy_read_timeout 60s; #\u914d\u7f6e\u70b92\uff0c\u5982\u679c\u6ca1\u6548\uff0c\u53ef\u4ee5\u8003\u8651\u8fd9\u4e2a\u65f6\u95f4\u914d\u7f6e\u957f\u4e00\u70b9\n            proxy_send_timeout 12s; #\u914d\u7f6e\u70b93\n        }\n        \n        # \u6570\u636e\u4e2d\u5fc3\u63a5\u53e3\u7aef\n        location \/police\/preprocess\/ {\n            proxy_pass   http:\/\/suntang-cdh4:8080\/police\/preprocess\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout 60s;\n            proxy_send_timeout 60s;\n            proxy_read_timeout 90s;\n        }\n        \n        # redirect server error pages to the static page \/50x.html\n        #\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n    }\n    server {\n        listen       9233;\n        server_name  127.0.0.1;\n\n\t      #\u6dfb\u52a0\u5934\u90e8\u4fe1\u606f    \n        proxy_set_header Cookie $http_cookie;\n        proxy_set_header X-Forwarded-Host $host;\n        proxy_set_header X-Forwarded-Server $host;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        #charset koi8-r;\n        #access_log  logs\/host.access.log  main;\n\n        location \/ {\n                 #vue\u9879\u76ee\u90e8\u7f72\u8def\u5f84\n                 root \/opt\/nginx\/dist_client\/dist;\n                 #\u89e3\u51b3\u9875\u9762\u5237\u65b0404\u95ee\u9898\n                 try_files $uri $uri\/ \/index.html last;\n                 index  index.html index.htm;               \n        }\n        #\u63a5\u53e3\u7aef\n        location \/police\/ {\n            proxy_pass   http:\/\/suntang-cdh4:8080\/police\/;\n            proxy_redirect default;\n            proxy_http_version 1.1;\n            proxy_connect_timeout   60;\n            proxy_send_timeout      60;\n            proxy_read_timeout      90;\n        }\n        error_page   500 502 503 504  \/50x.html;\n        location = \/50x.html {\n            root   html;\n        }\n    }\n}\n\n<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003\u5730\u5740\uff1a<\/p>\n\n\n\n<p>https:\/\/github.com\/rui-rui-an\/nginxpages<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u89e3\u6790\u7248 \u4e8c\u3001\u539f\u7248 \u4e09\u3001\u9879\u76ee\u4f7f\u7528\u7248 \u53c2\u8003\u5730\u5740\uff1a https:\/\/github.com\/rui-rui-an\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-llinuxstudy","category-nginxstudy"],"_links":{"self":[{"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9youx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":1,"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":328,"href":"https:\/\/www.9youx.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions\/328"}],"wp:attachment":[{"href":"https:\/\/www.9youx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9youx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9youx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}