{"id":263338,"date":"2023-03-07T09:06:52","date_gmt":"2023-03-07T01:06:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=263338"},"modified":"2023-02-03T23:46:52","modified_gmt":"2023-02-03T15:46:52","slug":"linux-unix-nginx","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-unix-nginx.html","title":{"rendered":"\u5728Linux\u548cUnix\u4e0a\u9690\u85cfNginx\u7248\u672c"},"content":{"rendered":"
\u4f7f\u7528 CLI \u663e\u793a\u5f53\u524d Nginx \u7248\u672c<\/strong><\/div>\n

Nginx\u5c06\u5728\u9519\u8bef\u9875\u9762\u548c\u201c\u670d\u52a1\u5668\u201d\u54cd\u5e94\u6807\u5934\u5b57\u6bb5\u4e2d\u663e\u793a\u7248\u672c\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u9a8c\u8bc1\uff1a \u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

$ curl -I https:\/\/your-domain\r\n$ curl -I https:\/\/www.cyberciti.biz\r\nHTTP\/2 200 server: nginx\/1.17.10 (Ubuntu)date: Tue, 23 Jun 2020 09:36:49 GMTcontent-type: text\/html; charset=UTF-8strict-transport-security: max-age=15768000x-whome: l-ncbz01-mg-wg<\/pre>\n

\u8fd9\u662f\u6211\u7684HTTP \/ 502\u9519\u8bef\u9875\u9762\u663e\u793a\u4fe1\u606f\u7684\u8f93\u51fa\uff1a<\/p>\n

\"\"<\/p>\n

\u4f7f\u7528server_tokens\u6307\u4ee4\u9690\u85cf Nginx \u7248\u672c<\/strong><\/div>\n

\u60a8\u9700\u8981\u5c06server_tokens\u8bbe\u7f6e\u4e3a off \u4ee5\u9690\u85cf Linux \u548c\u7c7b Unix \u7cfb\u7edf\u4e0a\u7684 Nginx \u670d\u52a1\u5668\u7248\u672c\u3002\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 vim\/nano\uff09\u7f16\u8f91\u60a8\u7684 nginx.conf \u6587\u4ef6\uff1a<\/p>\n

\u6211\u4eec\u53ea\u80fd\u5728 http\u3001\u670d\u52a1\u5668\u6216\u4f4d\u7f6e\u4e0a\u4e0b\u6587\u4e2d\u8bbe\u7f6eserver_tokens\u3002\u6211\u5c06\u6dfb\u52a0\u5230\u6211\u7684http\u90e8\u5206\uff1a\u8fd9\u662f\u5b83\u7684\u5916\u89c2\uff1a<\/p>\n

$ sudo vim \/etc\/nginx\/nginx.confserver_tokens off;\r\nhttp {        ## Basic Settings ##        charset utf-8;        sendfile on;        tcp_nopush on;        tcp_nodelay on;        log_not_found off;        keepalive_timeout 65;        types_hash_max_size 2048;        client_max_body_size 16M;        include \/etc\/nginx\/mime.types;        default_type application\/octet-stream;        ## Hide Nginx version ##        server_tokens   off;        ## Security headers for Nginx ##         add_header Strict-Transport-Security \"max-age=15768000\" always;        add_header X-Content-Type-Options \"nosniff\" always;        add_header X-Frame-Options \"SAMEORIGIN\" always;        add_header X-Xss-Protection \"1; mode=block\" always;        add_header Referrer-Policy  strict-origin-when-cross-origin;        add_header Feature-policy \"accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'\";        add_header Content-Security-Policy   \"default-src 'self' http: https: data: blob: 'unsafe-inline'\" always;        ## SSL Settings ##        ssl_protocols TLSv1.3;        access_log \/var\/log\/nginx\/access.log;        error_log \/var\/log\/nginx\/error.log;        ## Virtual Host Configs ##        include \/etc\/nginx\/conf.d\/*.conf;        include \/etc\/nginx\/sites-enabled\/*;}<\/pre>\n
\u6b63\u5e38\u91cd\u65b0\u542f\u52a8\u6216\u91cd\u65b0\u52a0\u8f7d Nginx \u670d\u52a1\u5668\uff1a<\/strong><\/div>\n
sudo nginx -tsudo nginx -s reload<\/pre>\n
\u9a8c\u8bc1 Nginx \u7248\u672c\u662f\u5426\u9690\u85cf<\/strong><\/div>\n

\u4f7f\u7528 curl \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a\uff1a\u770b\u6211\u7684 Nginx \u670d\u52a1\u5668\u6ca1\u6709\u663e\u793a\u4efb\u4f55\u7248\u672c\uff1a<\/p>\n

$ curl -I https:\/\/your-domain-name-here\r\n$ curl -I https:\/\/www.cyberciti.biz\r\n\r\nHTTP\/2 200 server: nginxdate: Tue, 23 Jun 2020 09:43:17 GMTcontent-type: text\/html; charset=UTF-8strict-transport-security: max-age=15768000<\/pre>\n

Firefox \u4e5f\u786e\u8ba4\u6211\u4e5f\u6210\u529f\u9690\u85cf\u4e86 Nginx \u7248\u672c\uff1a<\/p>\n

\"\"<\/p>\n

\u9690\u85cf Nginx \u7248\u672c\u7684\u5176\u4ed6\u53ef\u80fd\u503c<\/strong><\/div>\n

\u8bed\u6cd5\u5982\u4e0b\uff1a\u5728Linux\uff0c*BSD\u548cUnix\u4e0a\u7684\u9ed8\u8ba4\u8bbe\u7f6e\u5982\u4e0b\uff1a<\/p>\n

server_tokens on | off | build | string;\r\nserver_tokens on;<\/pre>\n
\u4ece\u670d\u52a1\u5668\u6807\u5934\u548c\u9519\u8bef\u9875\u4e2d\u5220\u9664\u7248\u672c<\/strong><\/div>\n

\u6211\u4eec\u53ef\u4ee5\u66f4\u6539\u4e3a\u4ee5\u4e0b\u503c\u6765\u542f\u7528\u6216\u7981\u7528\u53d1\u51fa nginx \u7248\u672c\uff1a
\non\uff1a\u663e\u793a\u7248\u672c\u53f7\u3002
\noff\uff1a\u5173\u95ed\u663e\u793a\u7248\u672c\u53f7\u3002
\nbuild\uff1a\u786e\u4fdd\u6211\u4eec\u53d1\u51fa\u4e00\u4e2a\u6784\u5efa\u540d\u79f0\u4ee5\u53canginx\u7248\u672c\u3002\u60a8\u5fc5\u987b\u62e5\u6709 Nginx \u7248\u672c 1.11.10\u3002
\nstring\uff1a\u4ec5\u9002\u7528\u4e8e\u5546\u4e1a\u8ba2\u9605\uff0c\u4ece\u7248\u672c 1.9.13 \u5f00\u59cb\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e26\u6709\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u663e\u793a\u8bbe\u7f6e\u9519\u8bef\u9875\u9762\u4e0a\u7684\u7b7e\u540d\u548c\u201c\u670d\u52a1\u5668\u201d\u54cd\u5e94\u6807\u5934\u5b57\u6bb5\u503c\u3002\u7a7a\u5b57\u7b26\u4e32\u7981\u7528\u201c\u670d\u52a1\u5668\u201d\u5b57\u6bb5\u7684\u53d1\u51fa\u3002<\/p>\n

\u5728 Nginx \u4e2d\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7248\u672c\u53f7<\/strong><\/div>\n

\u4f8b\u5982\uff0c\u5546\u4e1a\u8ba2\u9605\uff08Nginx Plus\uff09\u7528\u6237\u53ef\u4ee5\u5c06\u5176\u8bbe\u7f6e\u4e3a\u4f2a\u9020\u7684\u670d\u52a1\u5668\u7248\u672c\u548c\u81ea\u5b9a\u4e49\u540d\u79f0\uff1a \u4f7f\u7528\u670d\u52a1\u547d\u4ee4\u6216systemctl\u547d\u4ee4\u91cd\u65b0\u52a0\u8f7dNginx\u670d\u52a1\u5668\uff1a \u540c\u6837\uff0c\u4f7f\u7528 curl \u547d\u4ee4\u5bf9\u5176\u8fdb\u884c\u6d4b\u8bd5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

;$ service nginx reload$ curl -I http:\/\/127.0.0.1\/<\/pre>\n

\"\"<\/p>\n

\u9690\u85cf\u7248\u672c\u662f\u9ed8\u9ed8\u65e0\u95fb\u7684\u5b89\u5168<\/strong><\/div>\n

\u662f\u7684\uff0c\u5b83\u662f\u901a\u8fc7\u9690\u853d\u529f\u80fd\u7684\u5b89\u5168\u6027\u3002\u5b83\u662f\u7eb5\u6df1\u9632\u5fa1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f46\u662f\uff0c\u5b83\u4e0d\u5e94\u8be5\u662f\u4e3b\u8981\u7684\u9632\u5fa1\u5f62\u5f0f\u3002\u60a8\u9700\u8981\u7f16\u5199\u5b89\u5168\u4ee3\u7801\u3002\u5b89\u88c5\u9632\u706b\u5899\uff0c\u5c24\u5176\u662f WAF\uff08Web \u5e94\u7528\u7a0b\u5e8f\u9632\u706b\u5899\uff09\u3002\u6ca1\u6709\u7406\u7531\u66b4\u9732Nginx\u6216PHP\u6216Python\u7248\u672c\uff0c\u56e0\u4e3a\u5b83\u5bf9\u653b\u51fb\u8005\u53ef\u80fd\u662f\u6709\u7528\u7684\u4fe1\u606f\u3002\u8bf7\u8bb0\u4f4f\uff0cLinux \/ Unix\u64cd\u4f5c\u7cfb\u7edf\uff0cWeb apps \/ Nginx\u5e94\u8be5\u4fdd\u6301\u5b89\u5168\uff0c\u65e0\u8bbaNginx\u7248\u672c\u662f\u5426\u516c\u5f00\u3002\u4f46\u662f\uff0c\u6211\u4eec\u4e0d\u4f1a\u901a\u8fc7\u53d1\u5e03\u7248\u672c\u53f7\u6765\u7ed9\u653b\u51fb\u8005\u5e26\u6765\u4efb\u4f55\u597d\u5904\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Nginx\u5c06\u5728\u9519\u8bef\u9875\u9762\u548c\u201c\u670d\u52a1\u5668\u201d\u54cd\u5e94\u6807\u5934\u5b57\u6bb5\u4e2d\u663e\u793a\u7248\u672c\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u9a8c\u8bc1\uff1a \u793a\u4f8b\u8f93\u51fa\uff1a $ cu […]<\/p>\n","protected":false},"author":310,"featured_media":263354,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-263338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=263338"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263338\/revisions"}],"predecessor-version":[{"id":263352,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263338\/revisions\/263352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/263354"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=263338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=263338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=263338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}