{"id":759,"date":"2021-12-21T16:41:47","date_gmt":"2021-12-21T08:41:47","guid":{"rendered":"https:\/\/www.aiqinqin.info\/?p=759"},"modified":"2021-12-21T16:41:47","modified_gmt":"2021-12-21T08:41:47","slug":"nginx-%e7%a6%81%e6%ad%a2%e5%9b%bd%e5%a4%96ip%e8%ae%bf%e9%97%aedebian%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.aiqinqin.info\/?p=759","title":{"rendered":"Nginx \u7981\u6b62\u56fd\u5916ip\u8bbf\u95ee(debian\u7248\u672c)"},"content":{"rendered":"<ol>\n<li>\u53c2\u8003\u4e0b\u9762\u811a\u672c\u5b89\u88c5 Nginx<\/li>\n<\/ol>\n<pre><code class=\"\">#!\/bin\/bash\n## install nginx\nWORK_DIR=`mktemp -d`\napt install wget libpcre3 libpcre3-dev zlib1g-dev \\\n    openssl libssl-dev libxml2 libxml2-dev libxslt-dev  \\\n    gcc  make libgd-dev  libgeoip-dev  libperl-dev libmaxminddb* \ncd \/opt &amp;&amp; git clone https:\/\/github.com\/leev\/ngx_http_geoip2_module.git\n\ncd $WORK_DIR\nwget http:\/\/nginx.org\/download\/nginx-1.20.1.tar.gz\n\ntar zxvf nginx-1.20.1.tar.gz &amp;&amp; cd nginx-1.20.1\n.\/configure --prefix=\/opt\/nginx --user=apache --group=apache \\\n    --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module \\\n    --with-pcre --with-http_v2_module --with-http_dav_module \\\n    --with-http_flv_module --with-http_realip_module --with-http_addition_module \\\n    --with-http_xslt_module --with-http_sub_module --with-http_random_index_module \\\n    --with-http_degradation_module --with-http_secure_link_module --with-http_perl_module \\\n    --add-module=\/opt\/ngx_http_geoip2_module \\\n    --with-debug --with-file-aio --with-stream --with-ld-opt=-Wl,-E\nmake &amp;&amp; make install\ncd ~ &amp;&amp; [ -d $WORK_DIR ] &amp;&amp; rm $WORK_DIR -rf\n\n## \u6dfb\u52a0nginx\u8fd0\u884c\u8d26\u6237\ncat \/etc\/passwd | grep apache\nif [ $? -ne 0 ];then\n    groupadd apache\n    useradd -g apache -s \/sbin\/nologin -c \"apache\" apache\nfi\n<\/code><\/pre>\n<ol start=\"2\">\n<li>\u4e0b\u9762\u4e00\u4e2a\u793a\u4f8b\u7684 nginx \u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"\">user  apache;\nworker_processes  auto;\n\nevents {\n    worker_connections  65535;\n}\n\nhttp {\n    include       mime.types;\n    default_type  application\/octet-stream;\n    sendfile        on;\n    tcp_nopush     on;\n    keepalive_timeout  65;\n    gzip  on;\n\n    #  GeoLite2-Country.mmdb \u8fd9\u4e2a\u6587\u4ef6\u9700\u8981\u5230 'https:\/\/dev.maxmind.com' \u81ea\u884c\u4e0b\u8f7d\u5e76\u653e\u5230 ' \/usr\/share\/GeoIP' \u8fd9\u4e2a\u76ee\u5f55\u4e0b\n    geoip2 \/usr\/share\/GeoIP\/GeoLite2-Country.mmdb {\n        auto_reload 5m;\n        $geoip2_data_country_code country iso_code;\n    }\n\n    map $geoip2_data_country_code $allowed_country {\n        default yes;\n        CN no;\n    }\n\n    server {\n        listen       80;\n        server_name  localhost;\n\n        location \/ {\n            root   html;\n            index  index.html index.htm;\n        }\n\n        if ($allowed_country = yes) {\n            return 403;\n        }\n    }\n\n}\n\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u6d4b\u8bd5\u7684\u8bdd\u9700\u8981\u7528\u4e00\u4e2a\u56fd\u5916\u7684\u8282\u70b9\u8fdb\u884c\u6d4b\u8bd5<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u4e0b\u9762\u811a\u672c\u5b89\u88c5 Nginx #!\/bin\/bash ## install nginx WORK_DIR=`m [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-759","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=759"}],"version-history":[{"count":1,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/759\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}