{"id":500,"date":"2019-09-07T20:39:04","date_gmt":"2019-09-07T12:39:04","guid":{"rendered":"http:\/\/blog.lovexu.cc\/?p=500"},"modified":"2022-09-17T12:17:34","modified_gmt":"2022-09-17T04:17:34","slug":"%e8%bd%ac%e8%bd%bdnginx%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86frp%e7%bc%93%e5%ad%98%e5%8a%a0%e9%80%9fhttphttps","status":"publish","type":"post","link":"https:\/\/lox.im\/index.php\/500.html","title":{"rendered":"[\u8f6c\u8f7d]nginx\u53cd\u5411\u4ee3\u7406frp\u7f13\u5b58\u52a0\u901fhttp+https"},"content":{"rendered":"\n<div id=\"toc_container\" class=\"toc_light_blue no_bullets\">\n<p><span style=\"color: inherit; font-size: 2.44em; font-weight: 600;\">\u539f\u6587\u94fe\u63a5<\/span><\/p>\n<\/div>\n<p>frps\u5229\u7528nginx\u53cd\u4ee3\u7f13\u5b58\uff0chttp\u52a0\u901f<\/p>\n<h1><span id=\"i-2\">\u80cc\u666f\u63cf\u8ff0<\/span><\/h1>\n<p>\u7531\u4e8efrp\u7684http\u548chttps\uff0c\u90fd\u662f\u4ece\u7528\u6237\u7684\u670d\u52a1\u4e2d\u5b8c\u6574\u8f93\u51fa\u6570\u636e\u7684\uff0c\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u4f7f\u7528frp\u7684\u7528\u6237\uff0c\u7f51\u7edc\u6bd4\u8f83\u5dee\/\u4e0a\u4f20\u4f4e\uff0c\u6253\u5f00\u81ea\u5df1\u7684\u8fd9\u4e9b\u670d\u52a1\uff0c\u8981\u52a0\u8f7d\u5927\u534a\u5929\u7684\u3002<br \/>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528nginx\u7684\u53cd\u4ee3\u7f13\u5b58\uff0c\u628afrp\u7528\u6237\u7684http\u548chttps\u4e2d\u7684\u9759\u6001\u8d44\u6e90\u7f13\u5b58\u5230\u670d\u52a1\u5668\u672c\u5730\uff0c\u4ece\u800c\u51cf\u5c11frp\u7528\u6237\u672c\u8eab\u7684\u7f51\u7edc\u8d44\u6e90\u8bf7\u6c42\u8bbf\u95ee\uff0c\u76f4\u63a5\u7565\u8fc7\u5927\u90e8\u5206\uff0c\u4ece\u800c\u5728\u670d\u52a1\u5668\u52a0\u901f\u3002<br \/>\u6548\u679c\u662f\u62d4\u7fa4\u7684\uff01<\/p>\n<h1><span id=\"nginx\">nginx\u53cd\u5411\u4ee3\u7406\u7f13\u5b58\u914d\u7f6e<\/span><\/h1>\n<p>\u65b0\u5efa\u7f13\u5b58\u76ee\u5f55<\/p>\n<pre><code class=\"line-numbers hljs nginx\"><span class=\"hljs-attribute\">mkdir<\/span> -pv \/home\/nginx\/cache\n<\/code><\/pre>\n<p>\u8d4b\u4e88\u6743\u9650<\/p>\n<pre><code class=\"line-numbers hljs nginx\"><span class=\"hljs-attribute\">chmod<\/span> -R <span class=\"hljs-number\">777<\/span> \/home\/nginx\/cache\n<\/code><\/pre>\n<p>\u5728nginx.conf\u4e2dhttp{}\u91cc\u6dfb\u52a0\u4ee5\u4e0b\u53c2\u6570<\/p>\n<pre><code class=\"line-numbers hljs perl\">proxy_cache_path \/home\/nginx\/cache levels=<span class=\"hljs-number\">1<\/span>:<span class=\"hljs-number\">2<\/span> keys_zone=frp_cache:<span class=\"hljs-number\">100<\/span><span class=\"hljs-keyword\">m<\/span> max_size=<span class=\"hljs-number\">5<\/span>g inactive=<span class=\"hljs-number\">30<\/span>d;\nresolver <span class=\"hljs-number\">8.8<\/span>.<span class=\"hljs-number\">8.8<\/span>;\nserver {\n    <span class=\"hljs-keyword\">listen<\/span>       <span class=\"hljs-number\">80<\/span>;\n    server_name aiuyo.com;\n\n    <span class=\"hljs-comment\">#charset koi8-r;<\/span>\n    <span class=\"hljs-comment\">#access_log  \/var\/log\/nginx\/host.access.log  main;<\/span>\n\n    location \/ {\n        proxy_pass http:<span class=\"hljs-regexp\">\/\/<\/span>$host:<span class=\"hljs-number\">8680<\/span>;\n        proxy_redirect http:<span class=\"hljs-regexp\">\/\/<\/span>$host\/ http:<span class=\"hljs-regexp\">\/\/<\/span>$http_host\/;\n                proxy_set_header X-Real-IP $remote_addr;\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                proxy_set_header Host $host;\n    }\n\n        location ~* \\.(jpg|jpeg|gif|png|svg|css|scss|js|ico|xml|woff|woff2|ttf|otf|eot)$ {\n                proxy_pass http:<span class=\"hljs-regexp\">\/\/<\/span>$host:<span class=\"hljs-number\">8680<\/span>;\n                proxy_redirect http:<span class=\"hljs-regexp\">\/\/<\/span>$host\/ http:<span class=\"hljs-regexp\">\/\/<\/span>$http_host\/;\n                proxy_set_header X-Real-IP $remote_addr;\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                proxy_set_header Host $host;\n                proxy_cache frp_cache;\n                proxy_cache_key $uri$is_args$args;\n                proxy_cache_valid <span class=\"hljs-number\">200<\/span> <span class=\"hljs-number\">206<\/span> <span class=\"hljs-number\">301<\/span> <span class=\"hljs-number\">302<\/span> <span class=\"hljs-number\">304<\/span> <span class=\"hljs-number\">3<\/span>d;\n                expires <span class=\"hljs-number\">30<\/span>d;\n        }\n}\n\nserver{\n        <span class=\"hljs-keyword\">listen<\/span> <span class=\"hljs-number\">443<\/span> ssl;\n        ssl on;\n        server_name *.aiuyo.com;\n        ssl_certificate \/root\/.acme.sh\/aiuyo.com\/fullchain.cer;\n        ssl_certificate_key  \/root\/.acme.sh\/aiuyo.com\/aiuyo.com.key;\n        ssl_trusted_certificate \/root\/.acme.sh\/aiuyo.com\/ca.cer;\n\n        location \/ {\n                proxy_ssl_server_name on;\n                proxy_set_header X-Real-IP $remote_addr;\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                proxy_set_header X-Forwarded-Proto $scheme;\n                proxy_set_header Host $host:$server_port;\n                proxy_pass https:<span class=\"hljs-regexp\">\/\/<\/span>$host:<span class=\"hljs-number\">8643<\/span>; <span class=\"hljs-comment\">#\u901a\u8fc7\u57df\u540d\u8bbf\u95eefrp\u670d\u52a1<\/span>\n        }\n\n        location ~* \\.(jpg|jpeg|gif|png|svg|css|scss|js|ico|xml|woff|woff2|ttf|otf|eot)$ {\n                proxy_ssl_server_name on;\n                proxy_pass https:<span class=\"hljs-regexp\">\/\/<\/span>$host:<span class=\"hljs-number\">8643<\/span>; <span class=\"hljs-comment\">#\u901a\u8fc7\u57df\u540d\u8bbf\u95eefrp\u670d\u52a1<\/span>\n                proxy_redirect https:<span class=\"hljs-regexp\">\/\/<\/span>$host\/ https:<span class=\"hljs-regexp\">\/\/<\/span>$http_host\/;\n                proxy_set_header X-Real-IP $remote_addr;\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                proxy_set_header Host $host;\n                proxy_set_header X-Forwarded-proto https;\n                proxy_cache frp_cache;\n                proxy_cache_key $uri$is_args$args;\n                proxy_cache_valid <span class=\"hljs-number\">200<\/span> <span class=\"hljs-number\">206<\/span> <span class=\"hljs-number\">301<\/span> <span class=\"hljs-number\">302<\/span> <span class=\"hljs-number\">304<\/span> <span class=\"hljs-number\">3<\/span>d;\n                expires <span class=\"hljs-number\">30<\/span>d;\n        }\n}\n<\/code><\/pre>\n<h1><span id=\"i-3\">\u914d\u7f6e\u8bf4\u660e<\/span><\/h1>\n<p>(jpg|jpeg|gif|png|svg|css|scss|js|ico|xml|woff|woff2|ttf|otf|eot)\u4e3a\u9700\u8981\u8fdb\u884c\u7f13\u5b58\u7684\u9759\u6001\u8d44\u6e90\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u6216\u8005\u4fee\u6539\u3002<\/p>\n<p>proxy_cache_valid\u4e3a\u670d\u52a1\u5668\u7f13\u5b58\uff0c\u5176\u4e2d200 206 301 302 304\u4e3aHTTP\u72b6\u6001\u7801\uff08http:\/\/tool.chinaz.com\/pagestatus\/\uff09\u9488\u5bf9\u72b6\u6001\u7801\u7f13\u5b58\uff0c\u800c\u6700\u540e\u9762\u7684 30d \u4e3a\u7f13\u5b58\u8fc7\u671f\u65f6\u95f4\uff0c\u5f53\u7528\u6237\u6ca1\u6709\u5728\u8fd9\u4e2a\u6709\u6548\u65f6\u95f4\u5185\u8bbf\u95ee\u5230\u8fd9\u4e2a\u8d44\u6e90\uff0c\u5219\u4f1a\u8fc7\u671f\u6e05\u9664\uff0c\u76f4\u5230\u7528\u6237\u91cd\u65b0\u8bbf\u95ee\u5230\u8fd9\u4e2a\u8d44\u6e90\u5219\u91cd\u65b0\u7f13\u5b58\u3002<br \/>expires \u4e3a\u8bbf\u95ee\u7528\u6237\u672c\u5730\u7f13\u5b58<br \/>d \u5929\u6570 h \u5c0f\u65f6 m \u5206\u949f s \u79d2<\/p>\n<p>http:\/\/127.0.0.1:8680;\u76848080\u7aef\u53e3\u4e3a\u4f60frp.ini\u914d\u7f6e\u6587\u4ef6vhost_http_port = 8680\u7aef\u53e3<br \/>http:\/\/127.0.0.1:8643;\u76848443\u7aef\u53e3\u4e3a\u4f60frp.ini\u914d\u7f6e\u6587\u4ef6vhost_https_port = 8643\u7aef\u53e3<br \/>\u5bf9\u5e94\u7684frps.ini\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"line-numbers hljs ini\"><span class=\"hljs-comment\"># if you want to support virtual host, you must set the http port for listening (optional)<\/span>\n<span class=\"hljs-comment\"># <span class=\"hljs-doctag\">Note:<\/span> http port and https port can be same with bind_port<\/span>\n<span class=\"hljs-attr\">vhost_http_port<\/span> = <span class=\"hljs-number\">8680<\/span>\n<span class=\"hljs-attr\">vhost_https_port<\/span> = <span class=\"hljs-number\">8643<\/span>\n<\/code><\/pre>\n<p>\u5176\u4e2d\u7684\u7aef\u53e3\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u4fee\u6539\u3002<\/p>\n<p>\u914d\u7f6e\u6210\u529f\u540e\uff0c\u5e76\u4e14\u8bbf\u95ee\u76ee\u6807\u7f51\u7ad9\uff0c\u8ba9nginx\u8fdb\u884c\u7f13\u5b58\uff0c\u5728\/home\/nginx\/cache\u76ee\u5f55\u91cc\u4f1a\u751f\u6210\u591a\u4e2a\u7f13\u5b58\u76ee\u5f55\u548c\u6587\u4ef6\u3002<\/p>\n<h1><span id=\"nginx_httpsfrp_https\">\u5bf9\u4e8enginx https\u4ee3\u7406frp https\u7684\u7406\u89e3<\/span><\/h1>\n<p>\u6211\u7684\u7406\u89e3\u662f\u8fd9\u6837\u7684\uff1a<br \/>\u5982\u679c\u4f7f\u7528\u4e86\u81ea\u5b9a\u4e49\u57df\u540d\uff0cfrp\u662f\u6839\u636e$host\u503c\u5224\u65ad\u8be5\u5f80\u54ea\u4e2a\u5185\u7f51\u670d\u52a1\u8f6c\u53d1\u8bf7\u6c42\u7684\uff0c\u56e0\u6b64\u8f6c\u7ed9frp\u7684\u8bf7\u6c42\u4e2d\u4e00\u5b9a\u8981\u5305\u542b$host\uff0c\u5426\u5219frp\u65e0\u6cd5\u6b63\u5e38\u5904\u7406\u8bf7\u6c42\u3002<br \/>\u56e0\u6b64\u4ee5\u4e0b2\u4e2a\u914d\u7f6e\u5f88\u91cd\u8981\uff1a<\/p>\n<pre><code class=\"line-numbers hljs nginx\"><span class=\"hljs-attribute\">proxy_ssl_server_name<\/span> <span class=\"hljs-literal\">on<\/span>;\n<span class=\"hljs-attribute\">proxy_pass<\/span> https:\/\/<span class=\"hljs-variable\">$host<\/span>:8643; <span class=\"hljs-comment\">#\u901a\u8fc7\u57df\u540d\u8bbf\u95eefrp\u670d\u52a1<\/span>\n<\/code><\/pre>\n<p>proxy_pass\u4e2d\u4e0d\u80fd\u5199\u6210IP\u7684\u5f62\u5f0f\u3002<br \/>\u4e3e\u4e00\u4e2a\u6211\u7684\u4f8b\u5b50\uff0c\u6211\u5185\u7f51\u670d\u52a1\u5668192.168.2.99\u4e0a\u90e8\u7f72\u77402\u4e2a\u670d\u52a1\uff0celasticsearch\u548ckibana\uff0c\u7aef\u53e3\u5206\u522b\u662f9200\u548c5601\uff0c\u6211\u73b0\u5728\u60f3\u8981\u628a\u8fd92\u4e2a\u670d\u52a1\u7a7f\u900f\u51fa\u53bb\uff0c\u5e76\u914d\u7f6e\u6210https\u3002\u5177\u4f53\u914d\u7f6e\u5982\u4e0b\uff1a<br \/>frps.ini\u4e2d\u7684\u4e3b\u8981\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"line-numbers hljs shell\">[common]\n<span class=\"hljs-meta\">#<\/span><span class=\"bash\"> A literal address or host name <span class=\"hljs-keyword\">for<\/span> IPv6 must be enclosed<\/span>\n<span class=\"hljs-meta\">#<\/span><span class=\"bash\"> <span class=\"hljs-keyword\">in<\/span> square brackets, as <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-string\">\"[::1]:80\"<\/span>, <span class=\"hljs-string\">\"[ipv6-host]:http\"<\/span> or <span class=\"hljs-string\">\"[ipv6-host%zone]:80\"<\/span><\/span>\nbind_addr = 0.0.0.0\nbind_port = 7000\n\u2026\u2026\n<span class=\"hljs-meta\">#<\/span><span class=\"bash\"> <span class=\"hljs-keyword\">if<\/span> you want to support virtual host, you must <span class=\"hljs-built_in\">set<\/span> the http port <span class=\"hljs-keyword\">for<\/span> listening (optional)<\/span>\n<span class=\"hljs-meta\">#<\/span><span class=\"bash\"> Note: http port and https port can be same with bind_port<\/span>\nvhost_http_port = 8680\nvhost_https_port = 8643\n<\/code><\/pre>\n<p>\u7136\u540e\u901a\u8fc7\u4e0a\u8fb9\u914d\u7f6e\u7684nginx\u8fdb\u884c\u4ee3\u7406\u8f6c\u53d1\u8bf7\u6c42\u5230frp\u4e0a\u3002<br \/>frpc.ini\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre class=\"crayon-selected\"><code class=\"line-numbers hljs ini\"><span class=\"hljs-section\">[es]<\/span>\n<span class=\"hljs-attr\">type<\/span>=https\n<span class=\"hljs-attr\">custom_domains<\/span>=es.aiuyo.com\n<span class=\"hljs-attr\">local_ip<\/span>=<span class=\"hljs-number\">192.168<\/span>.<span class=\"hljs-number\">2.99<\/span>\n<span class=\"hljs-attr\">local_port<\/span>=<span class=\"hljs-number\">9200<\/span>\n<span class=\"hljs-attr\">use_encryption<\/span>=<span class=\"hljs-literal\">true<\/span>\n<span class=\"hljs-attr\">use_compression<\/span>=<span class=\"hljs-literal\">true<\/span>\n<span class=\"hljs-section\">\n[kb]<\/span>\n<span class=\"hljs-attr\">type<\/span>=https\n<span class=\"hljs-attr\">custom_domains<\/span>=kb.aiuyo.com\n<span class=\"hljs-attr\">local_ip<\/span>=<span class=\"hljs-number\">192.168<\/span>.<span class=\"hljs-number\">2.99<\/span>\n<span class=\"hljs-attr\">local_port<\/span>=<span class=\"hljs-number\">5601<\/span>\n<span class=\"hljs-attr\">use_encryption<\/span>=<span class=\"hljs-literal\">true<\/span>\n<span class=\"hljs-attr\">use_compression<\/span>=<span class=\"hljs-literal\">true<\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":350,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[4],"tags":[30],"class_list":["post-500","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-internet","tag-frp"],"_links":{"self":[{"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/posts\/500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":1,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions\/841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/media\/350"}],"wp:attachment":[{"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lox.im\/index.php\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}