{"id":2184,"date":"2022-02-10T11:28:41","date_gmt":"2022-02-10T03:28:41","guid":{"rendered":"https:\/\/199604.com\/?p=2184"},"modified":"2022-02-10T11:28:41","modified_gmt":"2022-02-10T03:28:41","slug":"%e5%b0%8f%e7%99%bd%e7%ba%a7%e5%88%ab-nginx-%e5%b8%b8%e7%94%a8%e9%85%8d%e7%bd%ae%e6%b8%85%e5%8d%95","status":"publish","type":"post","link":"https:\/\/199604.com\/2184","title":{"rendered":"\u5c0f\u767d\u7ea7\u522b Nginx \u5e38\u7528\u914d\u7f6e\u6e05\u5355"},"content":{"rendered":"<h1>\u5c0f\u767d\u7ea7\u522b Nginx \u5e38\u7528\u914d\u7f6e\u6e05\u5355<\/h1>\n<h2>\u4fa6\u542c\u7aef\u53e3<\/h2>\n<pre><code class=\"language-properties \">server {\n  # Standard HTTP Protocol\n  listen 80;\n  # Standard HTTPS Protocol\n  listen 443 ssl;\n  # For http2\n  listen 443 ssl http2;\n  # Listen on 80 using IPv6\n  listen [::]:80;\n  # Listen only on using IPv6\n  listen [::]:80 ipv6only=on;\n}\n<\/code><\/pre>\n<h2>\u8bbf\u95ee\u65e5\u5fd7<\/h2>\n<pre><code class=\"language-properties \">server {\n  # Relative or full path to log file\n  access_log \/path\/to\/file.log;\n  # Turn 'on' or 'off'\n  access_log on;\n}\n<\/code><\/pre>\n<h2>\u57df\u540d<\/h2>\n<pre><code class=\"language-properties \">server {\n  # Listen to yourdomain.com\n  server_name yourdomain.com;\n  # Listen to multiple domains\n  server_name yourdomain.com www.yourdomain.com;\n  # Listen to all domains\n  server_name *.yourdomain.com;\n  # Listen to all top-level domains\n  server_name yourdomain.*;\n  # Listen to unspecified Hostnames (Listens to IP address itself)\n  server_name \"\";\n}\n<\/code><\/pre>\n<h2>\u9759\u6001\u8d44\u6e90<\/h2>\n<pre><code class=\"language-properties \">server {\n  listen 80;\n  server_name yourdomain.com;\n  location \/ {\n    root \/path\/to\/website;\n  } \n}\n<\/code><\/pre>\n<h2>\u91cd\u5b9a\u5411<\/h2>\n<pre><code class=\"language-properties \">server {\n  listen 80;\n  server_name www.yourdomain.com;\n  return 301 http:\/\/yourdomain.com$request_uri;\n}\nserver {\n  listen 80;\n  server_name www.yourdomain.com;\n  location \/redirect-url {\n     return 301 http:\/\/otherdomain.com;\n  }\n}\n<\/code><\/pre>\n<h2>\u53cd\u5411\u4ee3\u7406<\/h2>\n<pre><code class=\"language-properties \">server {\n  listen 80;\n  server_name yourdomain.com;\n  location \/ {\n     proxy_pass http:\/\/0.0.0.0:3000;\n     # where 0.0.0.0:3000 is your application server (Ex: node.js) bound on 0.0.0.0 listening on port 3000\n  }\n}\n<\/code><\/pre>\n<h2>\u8d1f\u8f7d\u5747\u8861<\/h2>\n<pre><code class=\"language-properties \">upstream node_js {\n  server 0.0.0.0:3000;\n  server 0.0.0.0:4000;\n  server 123.131.121.122;\n}\nserver {\n  listen 80;\n  server_name yourdomain.com;\n  location \/ {\n     proxy_pass http:\/\/node_js;\n  }\n}\n<\/code><\/pre>\n<h2>SSL \u534f\u8bae<\/h2>\n<pre><code class=\"language-properties \">server {\n  listen 443 ssl;\n  server_name yourdomain.com;\n  ssl on;\n  ssl_certificate \/path\/to\/cert.pem;\n  ssl_certificate_key \/path\/to\/privatekey.pem;\n  ssl_stapling on;\n  ssl_stapling_verify on;\n  ssl_trusted_certificate \/path\/to\/fullchain.pem;\n  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n  ssl_session_timeout 1h;\n  ssl_session_cache shared:SSL:50m;\n  add_header Strict-Transport-Security max-age=15768000;\n}\n# Permanent Redirect for HTTP to HTTPS\nserver {\n  listen 80;\n  server_name yourdomain.com;\n  return 301 https:\/\/$host$request_uri;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u767d\u7ea7\u522b Nginx \u5e38\u7528\u914d\u7f6e\u6e05\u5355 \u4fa6\u542c\u7aef\u53e3 server { # Standard HTTP Protoco [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[260,283],"tags":[215],"class_list":["post-2184","post","type-post","status-publish","format-standard","hentry","category-linux","category-nginx","tag-nginx"],"_links":{"self":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/comments?post=2184"}],"version-history":[{"count":1,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2184\/revisions"}],"predecessor-version":[{"id":2185,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2184\/revisions\/2185"}],"wp:attachment":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/media?parent=2184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/categories?post=2184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/tags?post=2184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}