{"id":302,"date":"2023-02-24T22:06:12","date_gmt":"2023-02-24T14:06:12","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=302"},"modified":"2023-04-30T15:06:49","modified_gmt":"2023-04-30T07:06:49","slug":"nginx-related-configuration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/nginx-related-configuration\/","title":{"rendered":"Nginx \u76f8\u5173\u914d\u7f6e"},"content":{"rendered":"<h2>\u6a21\u62dfif\u591a\u91cd\u5224\u65ad<\/h2>\n<p>\u80cc\u666f\uff1a\u56e0\u4e3a\u6709\u4eba\u6076\u610f\u5237\u6211\u4eec\u4e00\u4e2a\u94fe\u63a5\uff0c\u62d2\u6389\u8fd9\u4e9b\u8bbf\u95ee<\/p>\n<p>\u4f2a\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">if ( $request ~ &quot;\/credit-user\/reg-get-code&quot;  &amp;&amp; $http_user_agent ~ okhttp ) { \n    rewrite ^\/(.*)$ https:\/\/www.iteblog.com\/$1 permanent; \n    #return 403;\n}<\/code><\/pre>\n<p>\u4f46\u53ef\u60dcNginx\u5e76\u4e0d\u652f\u6301\u8fd9\u79cd\u5199\u6cd5\uff0c\u53ea\u597d\u7528\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5\u8fdb\u884c\u591a\u91cd\u5224\u65ad\uff0c\u7ecf\u6d4b\u8bd5\u53ef\u7528\u3002<\/p>\n<pre><code class=\"language-json\">location \/ {\n    proxy_pass  http:\/\/127.0.0.1:8080;\n    set $flag 0;\n    if ( $request ~ &quot;\/credit-user\/reg-get-code&quot; ) {\n         set $flag &quot;${flag}1&quot;;\n       }\n    if ( $http_user_agent ~ okhttp ) {\n         set $flag &quot;${flag}2&quot;;\n       }\n    if ( $flag = &quot;012&quot; ) {\n        return 403;\n    }\n}<\/code><\/pre>\n<h2>\u57df\u540d\u91cd\u5b9a\u5411<\/h2>\n<p>\u6bd4\u5982\u8bbf\u95ee<code>http:\/\/***.com\/abc\/api\/jd\/id=1<\/code>\u6307\u5411<code>http:\/\/***.com\/api\/jd\/id=1<\/code><\/p>\n<pre><code class=\"language-bash\">location ~^\/abc\/ {\n    rewrite \/abc\/(.*) \/$1 break;\n}<\/code><\/pre>\n<h2>\u914d\u7f6e Vue history\u8def\u7531<\/h2>\n<p>1\u3001\u6839\u8def\u5f84\u914d\u7f6e<\/p>\n<pre><code class=\"language-bash\">server {\n    listen              80;\n    server_name         vue.xxx.com;\n\n    location  \/ {\n        index  index.html index.htm;\n        root   \/var\/www\/channelGift\/;  #vue\u9879\u76ee\u8def\u5f84\n        try_files $uri $uri\/ \/index.html;\n    }\n}<\/code><\/pre>\n<p>2\u3001\u975e\u6839\u76ee\u5f55\u914d\u7f6e<\/p>\n<pre><code class=\"language-bash\">server {\n    listen              80;\n    server_name         a.xxx.com;   #a\u57df\u540d\n\n    location \/ {\n        index  index.html index.htm;\n        root   \/var\/www\/a;    #a\u57df\u540d\u6839\u76ee\u5f55\n        error_page   500 502 503 504 \/index.html;\n    }\n    location  ^~ \/channelGift {\n        alias  \/var\/www\/b\/;    #vue\u9879\u76ee\u8def\u5f84\n        index  index.html;\n        try_files $uri $uri\/ \/channelGift\/index.html;   #\u4e0d\u8981\u7528\u7edd\u5bf9\u8def\u5f84\uff0c\u5982 \/var\/www\/channelGift\/index.html\n    }\n}<\/code><\/pre>\n<p>\u8fd8\u5e94\u8be5\u5728VUE\u9879\u76ee\u91cc\u628a\u6bcf\u4e2a\u8def\u5f84\u52a0\u4e0a<code>\/channelGift<\/code>\u8fd9\u4e00\u6bb5\uff08\u6216\u8005\u6307\u5b9a<code>base: &#039;\/channelGift\/&#039;<\/code>\uff09\uff0c\u8981\u4e0d\u9875\u9762\u4f1a\u663e\u793a\u4e3a\u7a7a\u767d\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u8fd0\u7ef4\/Vue\u8def\u7531\u57fa\u8def\u5f84\u914d\u7f6e.png\" alt=\"Vue\u8def\u7531\u57fa\u8def\u5f84\u914d\u7f6e\" \/><\/p>\n<p>\u8bbf\u95ee\u65f6\u4f7f\u7528\u4e0b\u9762\u8def\u5f84\u5373\u53ef\u8bbf\u95ee<\/p>\n<pre><code class=\"language-bash\">http:\/\/a.xxx.com\/channelGift\/product-list.html?fcode=1a399819<\/code><\/pre>\n<h2>\u5f00\u542fjs\u538b\u7f29<\/h2>\n<p>\u4fee\u6539Nginx\u53c2\u6570\uff0c\u5f00\u542fgzip\uff0c\u538b\u7f29\u7c7b\u578b<code>gzip_types<\/code>\u4e2d\u7684<code>application\/x-javascript<\/code>\u5e76\u4e0d\u662f\u4ee3\u8868javascript\uff0c\u771f\u6b63\u4ee3\u8868javascript\u7684\u662f\uff1a<code>application\/javascript<\/code>\uff0c\u6240\u4ee5\u8fd8\u9700\u8981\u5728<code>gzip_types<\/code>\u4e2d\u6dfb\u52a0\u8fdb\u53bb\u3002\u7136\u540e\u91cd\u542fNginx<\/p>\n<pre><code class=\"language-bash\">http {\n    gzip on;\n    gzip_min_length 10k;\n    gzip_comp_level 6;\n    gzip_static on;\n    gzip_types text\/html text\/plain application\/x-javascript application\/javascript text\/css application\/xml text\/javascript  image\/jpeg image\/gif image\/png;\n}<\/code><\/pre>\n<p>\u6d4b\u8bd5\uff1a\u5982\u679c\u8fd4\u56de\u7ed3\u679c\u6709<code>Content-Encoding: gzip<\/code>\u8bf4\u660e\u538b\u7f29\u6210\u529f<\/p>\n<pre><code class=\"language-bash\"># curl -I -H &quot;Accept-Encoding: gzip, deflate&quot; &quot;http:\/\/www.*****.com\/css\/chunk-vendors.728eb7d9.css&quot;\nHTTP\/1.1 200 OK\nServer: nginx\/1.12.2\nDate: Sat, 12 Oct 2019 09:54:39 GMT\nContent-Type: text\/css\nLast-Modified: Fri, 11 Oct 2019 11:43:45 GMT\nConnection: keep-alive\nETag: W\/&quot;5da06af1-39032&quot;\nExpires: Tue, 22 Oct 2019 09:54:39 GMT\nCache-Control: max-age=864000\nContent-Encoding: gzip<\/code><\/pre>\n<p>\u6216\u8005\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u91cc\u67e5\u770b\uff0cresponse headers \u6709\u5185\u5bb9<code>Content-Encoding: gzip<\/code>\u5c31\u662f\u5f00\u542f\u4e86gzip<\/p>\n<p>\u6ca1\u6709\u5f00\u542fgzip\uff0c\u5219\u5728request headers \u91cc\u663e\u793a<code>Accept-Encoding: gzip, deflate<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6a21\u62dfif\u591a\u91cd\u5224\u65ad \u80cc\u666f\uff1a\u56e0\u4e3a\u6709\u4eba\u6076\u610f\u5237\u6211\u4eec\u4e00\u4e2a\u94fe\u63a5\uff0c\u62d2\u6389\u8fd9\u4e9b\u8bbf\u95ee \u4f2a\u4ee3\u7801\u5982\u4e0b\uff1a if ( $request ~ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[25],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}