{"id":321,"date":"2016-07-26T12:20:17","date_gmt":"2016-07-26T04:20:17","guid":{"rendered":"http:\/\/www.isway.cn\/?p=321"},"modified":"2019-01-19T19:00:53","modified_gmt":"2019-01-19T11:00:53","slug":"321","status":"publish","type":"post","link":"https:\/\/www.isway.cn\/?p=321","title":{"rendered":"\u4f7f\u7528Nginx\u53cd\u5411\u4ee3\u7406Google\uff08\u652f\u6301HTTP\/2\u534f\u8bae\uff09"},"content":{"rendered":"<p>\u73af\u5883\uff1aUbuntu 14.04 (32bit\u621664bit)<br \/>\n\u672c\u6587\u6838\u5fc3\u5185\u5bb9\u6765\u81eahttps:\/\/ttt.tt\/162\uff0c\u611f\u8c22\u4f5c\u8005\u3002\u4e5f\u975e\u5e38\u611f\u8c22\u611f\u8c22wen.lu\u7684\u5f00\u6e90\u3002<br \/>\n\u5728\u770b\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u524d\uff0c\u9996\u5148\u4f60\u5f97\u51c6\u5907\u4e00\u53f0\u5899\u5916\u7684\u670d\u52a1\u5668\u6216 VPS\uff0c\u672c\u6587\u9ed8\u8ba4\u7528 root \u7528\u6237\uff0c\u5e76\u64cd\u4f5c\u5728\u7cfb\u7edf\u7684 \/root \u76ee\u5f55\u4e0b\uff0c\u4e3a\u4e86\u5b89\u5168\u8003\u8651\uff0c\u8bf7\u81ea\u884c\u66f4\u6362\u76ee\u5f55\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4e00\u3001\u7f16\u8bd1\u5b89\u88c5Nginx<br \/>\n1\u3001\u5b89\u88c5\u524d\u7684\u51c6\u5907\uff1a\u66f4\u65b0\u7cfb\u7edf<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">apt-get update &amp;&amp; apt-get upgrade<\/pre>\n<p>2\u3001\u5b89\u88c5Nginx\u9700\u8981\u7684\u5305\u548cGit<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">apt-get install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential git<\/pre>\n<p>3\u3001\u65b0\u5efa\u7acb\u4e2a Nginx \u76ee\u5f55\uff0c\u65b9\u4fbf\u7ba1\u7406<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">mkdir nginx &amp;&amp; cd nginx<\/pre>\n<p>4\u3001Nginx \u4ece1.9.5\u5f00\u59cb\u652f\u6301http\/2\u534f\u8bae\uff0c\u6211\u4eec\u9009\u62e9Stable version\uff0c\u622a\u81f3\u5230\u5199\u8fd9\u7bc7\u6559\u7a0b\uff0cStable version\u7248\u672c\u6700\u65b0\u4e3a1.10.1\u3002\u4e0b\u8f7dopenssl\uff0c\u81f3\u5c11\u9700\u89811.0.2\u3002\u5982\u679c\u5b9e\u9645\u7248\u672c\u4e0e\u672c\u6587\u4e0d\u7b26\uff0c\u8bf7\u6ce8\u610f\u4fee\u6539\u547d\u4ee4\u4e2d\u7684\u8def\u5f84\uff08\u4f1a\u5728\u6d89\u53ca\u5230\u7684\u6b65\u9aa4\u4e2d\u63d0\u9192\uff09<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">wget http:\/\/nginx.org\/download\/nginx-1.10.1.tar.gz\nwget https:\/\/www.openssl.org\/source\/openssl-1.0.2h.tar.gz\ntar -xvf nginx-1.10.1.tar.gz\ntar -xvf openssl-1.0.2h.tar.gz<\/pre>\n<p>5\u3001\u7528Git\u514b\u9686\u4e24\u4e2aNginx\u6a21\u5757\uff0c\u4e00\u4e2a\u662fwen.lu\u5f00\u6e90\u7684ngx_http_google_filter_module\uff0c\u53e6\u4e00\u4e2a\u662f Nginx \u66ff\u6362\u5173\u952e\u8bcd\u6a21\u5757 ngx_http_substitutions_filter_module<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">git clone https:\/\/github.com\/cuber\/ngx_http_google_filter_module\ngit clone https:\/\/github.com\/yaoweibin\/ngx_http_substitutions_filter_module<\/pre>\n<p>6\u3001\u8fdb\u5165 Nginx \u76ee\u5f55\u5e76\u521b\u5efa\u4e2a Nginx \u4e34\u65f6\u6587\u4ef6\u5939\uff0c\u8bf7\u6ce8\u610f\u8def\u5f84<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">cd nginx-1.10.1\nmkdir \/var\/tmp\/nginx<\/pre>\n<p>7\u3001\u4f7f\u7528\u4e0b\u9762\u7684\u53c2\u6570\u5f00\u59cb\u7f16\u8bd1\uff0c\u8bf7\u6ce8\u610f\u7ed3\u5c3eopenssl\u7684\u8def\u5f84<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">.\/configure --prefix=\/usr --conf-path=\/etc\/nginx\/nginx.conf --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/lock\/nginx.lock --http-client-body-temp-path=\/var\/tmp\/nginx\/client --http-proxy-temp-path=\/var\/tmp\/nginx\/proxy --http-fastcgi-temp-path=\/var\/tmp\/nginx\/fastcgi --http-scgi-temp-path=\/var\/tmp\/nginx\/scgi --http-uwsgi-temp-path=\/var\/tmp\/nginx\/uwsgi --with-http_ssl_module --with-http_gzip_static_module --add-module=\/root\/nginx\/ngx_http_google_filter_module --add-module=\/root\/nginx\/ngx_http_substitutions_filter_module --with-http_ssl_module --with-http_v2_module --with-openssl=\/root\/nginx\/openssl-1.0.2h<\/pre>\n<p>8\u3001\u6ca1\u95ee\u9898\u4ee5\u540e\u76f4\u63a5\u7528 make \u5b89\u88c5<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">make &amp;&amp; make install<\/pre>\n<p>\u4e8c\u3001\u5f00\u542f Nginx \u670d\u52a1<br \/>\n\u9ed8\u8ba4\u8fd9\u4e48\u5b89\u88c5\u597d\u4ee5\u540e\u6bcf\u6b21\u68c0\u67e5\u914d\u7f6e\u3001\u91cd\u542f\u4e4b\u7c7b\u7684\u64cd\u4f5c\u7565\u9ebb\u70e6\uff0c\u6240\u4ee5\u6211\u4eec\u6a21\u4eff Ubuntu 14.04 \u5b98\u65b9\u6e90\uff0c\u7ed9\u7cfb\u7edf\u8bbe\u7f6e\u4e2a nginx \u670d\u52a1\uff0c\u65b9\u4fbf\u6211\u4eec\u68c0\u67e5\u914d\u7f6e\u3001\u542f\u52a8\u91cd\u542f\u5173\u95ed Nginx \u4ee5\u53ca\u5f00\u673a\u81ea\u52a8\u542f\u52a8 Nginx<br \/>\n1\u3001\u8fdb\u5165\u7cfb\u7edf\u7684 \/etc\/init.d \u76ee\u5f55<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">cd \/etc\/init.d\/<\/pre>\n<p>2\u3001\u65b0\u5efa\u5e76\u7f16\u8f91\u4e00\u4e2a nginx \u6587\u4ef6<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vi nginx<\/pre>\n<p>3\u3001\u5177\u4f53\u5185\u5bb9\u5982\u4e0b<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#!\/bin\/sh\n### BEGIN INIT INFO\n# Provides: nginx\n# Required-Start: $local_fs $remote_fs $network $syslog\n# Required-Stop: $local_fs $remote_fs $network $syslog\n# Default-Start: 2 3 4 5\n# Default-Stop: 0 1 6\n# Short-Description: starts the nginx web server\n# Description: starts nginx using start-stop-daemon\n### END INIT INFO\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin\nDAEMON=\/usr\/sbin\/nginx\nNAME=nginx\nDESC=nginx\n# Include nginx defaults if available\nif [ -f \/etc\/default\/nginx ]; then\n. \/etc\/default\/nginx\nfi\ntest -x $DAEMON || exit 0\nset -e\n. \/lib\/lsb\/init-functions\ntest_nginx_config() {\nif $DAEMON -t $DAEMON_OPTS &gt;\/dev\/null 2&gt;&amp;1; then\nreturn 0\nelse\n$DAEMON -t $DAEMON_OPTS\nreturn $?\nfi\n}\ncase \"$1\" in\nstart)\necho -n \"Starting $DESC: \"\ntest_nginx_config\n# Check if the ULIMIT is set in \/etc\/default\/nginx\nif [ -n \"$ULIMIT\" ]; then\n# Set the ulimits\nulimit $ULIMIT\nfi\nstart-stop-daemon --start --quiet --pidfile \/var\/run\/$NAME.pid \\\n--exec $DAEMON -- $DAEMON_OPTS || true\necho \"$NAME.\"\n;;\nstop)\necho -n \"Stopping $DESC: \"\nstart-stop-daemon --stop --quiet --pidfile \/var\/run\/$NAME.pid \\\n--exec $DAEMON || true\necho \"$NAME.\"\n;;\nrestart|force-reload)\necho -n \"Restarting $DESC: \"\nstart-stop-daemon --stop --quiet --pidfile \\\n\/var\/run\/$NAME.pid --exec $DAEMON || true\nsleep 1\ntest_nginx_config\n# Check if the ULIMIT is set in \/etc\/default\/nginx\nif [ -n \"$ULIMIT\" ]; then\n# Set the ulimits\nulimit $ULIMIT\nfi\nstart-stop-daemon --start --quiet --pidfile \\\n\/var\/run\/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true\necho \"$NAME.\"\n;;\nreload)\necho -n \"Reloading $DESC configuration: \"\ntest_nginx_config\nstart-stop-daemon --stop --signal HUP --quiet --pidfile \/var\/run\/$NAME.pid \\\n--exec $DAEMON || true\necho \"$NAME.\"\n;;\nconfigtest|testconfig)\necho -n \"Testing $DESC configuration: \"\nif test_nginx_config; then\necho \"$NAME.\"\nelse\nexit $?\nfi\n;;\nstatus)\nstatus_of_proc -p \/var\/run\/$NAME.pid \"$DAEMON\" nginx &amp;&amp; exit 0 || exit $?\n;;\n*)\necho \"Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}\" &gt;&amp;2\nexit 1\n;;\nesac\nexit 0<\/pre>\n<p>4\u3001\u8d4b\u4e88\u6743\u9650\u5e76\u589e\u52a0\u5230\u7cfb\u7edf\u670d\u52a1<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">sudo chmod +x .\/nginx\nsudo update-rc.d nginx defaults<\/pre>\n<p>\u4e09\u3001\u4fee\u6539\u9ed8\u8ba4\u7684 nginx.conf \u914d\u7f6e\u6587\u4ef6<br \/>\n\u9ed8\u8ba4\u5b98\u65b9\u7684\u914d\u7f6e\u6587\u4ef6\u5199\u7684\u5f88\u7b80\u5355\uff0c\u8fd9\u91cc\u6211\u4eec\u4e5f\u6a21\u4eff Ubuntu 14.04 \u5b98\u65b9\u6e90\u4fee\u6539\u4e00\u4e2a\u9002\u5408\u6211\u4eec\u7684 Nginx \u914d\u7f6e<br \/>\n1\u3001\u7f16\u8f91 \/etc\/nginx\/nginx.conf<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vi \/etc\/nginx\/nginx.conf<\/pre>\n<p>\u5177\u4f53\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">worker_processes auto; \/\/\u6839\u636eCPU\u6838\u5fc3\u6570\u586b\u5199\uff0c\u4e0d\u786e\u5b9a\u5c31auto\npid \/var\/run\/nginx.pid;\nevents {\nworker_connections 768;\n}\nhttp {\nsendfile on;\ntcp_nopush on;\ntcp_nodelay on;\nkeepalive_timeout 65;\ntypes_hash_max_size 2048;\nserver_tokens off;\naccess_log \/var\/log\/nginx\/access.log;\nerror_log \/var\/log\/nginx\/error.log;\nproxy_temp_file_write_size 128k;\nproxy_temp_path \/var\/cache\/nginx\/temp;\nproxy_cache_path \/var\/cache\/nginx\/cache levels=1:2 keys_zone=cache_one:100m inactive=7d max_size=10g;\ngzip_static on;\ngzip on;\ngzip_disable \"msie6\";\ninclude \/etc\/nginx\/sites-enabled\/*;\n}<\/pre>\n<p>2\u3001\u65b0\u5efa\u51e0\u4e2a\u5fc5\u8981\u7684\u6587\u4ef6\u5939\uff1a\u5176\u4e2d \/etc\/nginx\/sites-enabled \u7528\u6765\u653e\u6211\u4eec\u7684\u7f51\u7ad9\u914d\u7f6e\u6587\u4ef6\uff0c\/var\/log\/nginx \u7528\u6765\u653e log \u65e5\u5fd7\u6587\u4ef6\uff0c\/var\/cache\/nginx\/cache \u548c \/var\/cache\/nginx\/temp \u5219\u662f Nginx \u53cd\u4ee3\u7f13\u5b58\u6587\u4ef6\u5939\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">mkdir -p \/etc\/nginx\/sites-enabled\nmkdir -p \/var\/log\/nginx\nmkdir -p \/var\/cache\/nginx\/cache\nmkdir -p \/var\/cache\/nginx\/temp<\/pre>\n<p>3\u3001\u68c0\u67e5 Nginx \u914d\u7f6e\uff0c\u76f4\u63a5\u8fd0\u884c nginx -t \u5982\u679c\u8f93\u51fa\u5982\u4e0b\u63d0\u793a\uff0c\u5219\u4e00\u5207\u6b63\u5e38<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/pre>\n<p>\u56db\u3001\u5f00\u542f Nginx SSL \u652f\u6301\uff08\u4f7f\u7528Let\u2019s Encrypt\u514d\u8d39\u8bc1\u4e66\u8bf7\u53c2\u8003https:\/\/www.isway.cn\/?p=352\uff09<br \/>\n1\u3001\u4e3a\u4e86\u7ba1\u7406\u65b9\u4fbf\uff0c\u6211\u4eec\u5efa\u7acb\u4e2a ssl \u76ee\u5f55<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">mkdir -p \/root\/ssl &amp;&amp; cd \/root\/ssl<\/pre>\n<p>2\u3001\u8fd0\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u751f\u6210 example.com.key \u548c example.com.csr\uff08\u8bf7\u81ea\u884c\u5c06example.com\u6539\u6210\u81ea\u5df1\u7684\u57df\u540d\uff09<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">openssl req -new -newkey rsa:2048 -nodes -out example.com.csr -keyout example.com.key -subj \"\/C=US\/ST=CA\/L=Los Angeles\/O=Example Inc.\/OU=Web Security\/CN=example.com\"<\/pre>\n<p>\u5982\u679c\u662f\u6cdb\u57df\u540d\u8bc1\u4e66\uff0c\u6700\u540e\u7684\u57df\u540d\u6539\u6210 *.example.com<br \/>\n3\u3001\u7136\u540e\u628a csr \u6587\u4ef6\u63d0\u4ea4\u7ed9\u4f60\u7684 SSL \u8bc1\u4e66\u5546\uff0c\u9a8c\u8bc1\u597d\u57df\u540d\u4ee5\u540e\u4f1a\u9881\u53d1\u7ed9\u4f60\u4e00\u4e2a .crt \u6587\u4ef6\uff0c\u6211\u4eec\u547d\u540d\u4e3a example.com.crt<br \/>\n4\u3001\u63a5\u7740\u6211\u4eec\u65b0\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u6765\u53cd\u4ee3 Google\uff1a\u8bf7\u81ea\u884c\u66f4\u6362\u914d\u7f6e\u6587\u4ef6\u91cc\u7684\u57df\u540d\u548c\u8bc1\u4e66\u6587\u4ef6\u540d<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vi \/etc\/nginx\/sites-enabled\/google.conf<\/pre>\n<p>\u5177\u4f53\u914d\u7f6e\u5982\u4e0b<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">server {\nlisten 80;\nserver_name example.com;\nreturn 301 https:\/\/example.com$request_uri;\n}\nserver {\nlisten 443 ssl http2;\nserver_name example;\nssl on;\nssl_certificate \/root\/ssl\/example.com.crt;\nssl_certificate_key \/root\/ssl\/example.com.key;\nssl_prefer_server_ciphers on;\nssl_protocols TLSv1 TLSv1.1 TLSv1.2;\nssl_ciphers EECDH+aRSA+AES;\nkeepalive_timeout 70;\nssl_session_cache shared:SSL:10m;\nssl_session_timeout 10m;\nresolver 8.8.8.8;\nlocation \/ {\ngoogle on;\ngoogle_scholar on;\n}\n}<\/pre>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u4fdd\u5b58\u540e\u91cd\u542f\u4e0b Nginx<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">service nginx restart<\/pre>\n<p>OK\uff0c\u5927\u529f\u544a\u6210\uff01\u6d4f\u89c8\u5668\u91cc\u8bbf\u95ee https:\/\/example.com\/ \u770b\u770b\u662f\u5426\u5df2\u7ecf\u53ef\u4ee5\u53cd\u4ee3 Google \u4e86\u3002<br \/>\n\u3010\u5b8c\u3011<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883\uff1aUbuntu 14.04 (32bit\u621664bit) \u672c\u6587\u6838\u5fc3\u5185\u5bb9\u6765\u81eahttps:\/\/ttt.tt\/16&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/www.isway.cn\/?p=321\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-web","category-tech"],"_links":{"self":[{"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.isway.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321"}],"version-history":[{"count":3,"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":394,"href":"https:\/\/www.isway.cn\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/394"}],"wp:attachment":[{"href":"https:\/\/www.isway.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.isway.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.isway.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}