{"id":52277,"date":"2024-10-09T01:17:18","date_gmt":"2024-10-08T17:17:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/52277\/"},"modified":"2024-11-14T10:39:37","modified_gmt":"2024-11-14T02:39:37","slug":"ubuntu-%e4%b8%8b%e7%b7%a8%e8%ad%af%e5%ae%89%e8%a3%9d-nginx-%e5%8f%8a%e7%9b%b8%e9%97%9c%e8%a8%ad%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/52277\/","title":{"rendered":"Ubuntu \u4e0b\u7de8\u8b6f\u5b89\u88dd Nginx \u53ca\u76f8\u95dc\u8a2d\u7f6e"},"content":{"rendered":"<h1 id=\"ubuntu-%e4%b8%8b%e7%b7%a8%e8%ad%af%e5%ae%89%e8%a3%9d-nginx-%e5%8f%8a%e7%9b%b8%e9%97%9c%e8%a8%ad%e7%bd%ae-VodnhiPjOL\">Ubuntu \u4e0b\u7de8\u8b6f\u5b89\u88dd Nginx \u53ca\u76f8\u95dc\u8a2d\u7f6e<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u5167\u5bb9\u7684\u63d0\u4f9b\u3001\u53cd\u5411\u4ee3\u7406\u3001\u8ca0\u8f09\u5747\u8861\u7b49\u5834\u666f\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e0b\u7de8\u8b6f\u5b89\u88dd Nginx\uff0c\u4e26\u9032\u884c\u76f8\u95dc\u8a2d\u7f6e\uff0c\u4ee5\u4fbf\u65bc\u7528\u6236\u80fd\u5920\u66f4\u597d\u5730\u638c\u63e1\u9019\u4e00\u904e\u7a0b\u3002<\/p>\n<h2 id=\"%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-VodnhiPjOL\">\u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684 Ubuntu \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u7de8\u8b6f Nginx \u6240\u9700\u7684\u4f9d\u8cf4\u5305\uff1a<\/p>\n<pre><code>sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev<\/code><\/pre>\n<h2 id=\"%e4%b8%8b%e8%bc%89-nginx-%e6%ba%90%e7%a2%bc-VodnhiPjOL\">\u4e0b\u8f09 Nginx \u6e90\u78bc<\/h2>\n<p>\u60a8\u53ef\u4ee5\u5f9e Nginx \u7684\u5b98\u65b9\u7db2\u7ad9\u4e0b\u8f09\u6700\u65b0\u7248\u672c\u7684\u6e90\u78bc\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4e0b\u8f09\uff1a<\/p>\n<pre><code>wget http:\/\/nginx.org\/download\/nginx-1.23.0.tar.gz<\/code><\/pre>\n<p>\u4e0b\u8f09\u5b8c\u6210\u5f8c\uff0c\u89e3\u58d3\u7e2e\u6e90\u78bc\u5305\uff1a<\/p>\n<pre><code>tar -zxvf nginx-1.23.0.tar.gz<\/code><\/pre>\n<h2 id=\"%e7%b7%a8%e8%ad%af-nginx-VodnhiPjOL\">\u7de8\u8b6f Nginx<\/h2>\n<p>\u9032\u5165\u89e3\u58d3\u5f8c\u7684\u76ee\u9304\uff1a<\/p>\n<pre><code>cd nginx-1.23.0<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u914d\u7f6e\uff1a<\/p>\n<pre><code>.\/configure --prefix=\/usr\/local\/nginx --with-http_ssl_module --with-pcre<\/code><\/pre>\n<p>\u9019\u88e1\u7684\u53c3\u6578\u6307\u5b9a\u4e86 Nginx \u7684\u5b89\u88dd\u8def\u5f91\u4ee5\u53ca\u555f\u7528 SSL \u6a21\u584a\u548c PCRE \u6a21\u584a\u3002\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u958b\u59cb\u7de8\u8b6f\uff1a<\/p>\n<pre><code>make<\/code><\/pre>\n<p>\u7de8\u8b6f\u5b8c\u6210\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Nginx\uff1a<\/p>\n<pre><code>sudo make install<\/code><\/pre>\n<h2 id=\"%e5%95%9f%e5%8b%95-nginx-VodnhiPjOL\">\u555f\u52d5 Nginx<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Nginx\uff1a<\/p>\n<pre><code>sudo \/usr\/local\/nginx\/sbin\/nginx<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5 Nginx \u662f\u5426\u6210\u529f\u555f\u52d5\uff0c\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165 <code>http:\/\/your_server_ip<\/code>\uff0c\u5982\u679c\u770b\u5230 Nginx \u7684\u6b61\u8fce\u9801\u9762\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-VodnhiPjOL\">\u914d\u7f6e Nginx<\/h2>\n<p>Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4f4d\u65bc <code>\/usr\/local\/nginx\/conf\/nginx.conf<\/code>\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b\u4e26\u9032\u884c\u4fee\u6539\uff1a<\/p>\n<pre><code>sudo nano \/usr\/local\/nginx\/conf\/nginx.conf<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u914d\u7f6e\u7bc4\u4f8b\uff0c\u5c07\u4f3a\u670d\u5668\u7684\u6839\u76ee\u9304\u8a2d\u7f6e\u70ba <code>\/var\/www\/html<\/code>\uff1a<\/p>\n<pre><code>server {\n    listen       80;\n    server_name  localhost;\n\n    location \/ {\n        root   \/var\/www\/html;\n        index  index.html index.htm;\n    }\n\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n        root   html;\n    }\n}<\/code><\/pre>\n<p>\u4fee\u6539\u5b8c\u6210\u5f8c\uff0c\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u3002\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u91cd\u65b0\u52a0\u8f09 Nginx \u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo \/usr\/local\/nginx\/sbin\/nginx -s reload<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e7%bd%ae%e9%98%b2%e7%81%ab%e7%89%86-VodnhiPjOL\">\u8a2d\u7f6e\u9632\u706b\u7246<\/h2>\n<p>\u5982\u679c\u60a8\u7684\u4f3a\u670d\u5668\u555f\u7528\u4e86\u9632\u706b\u7246\uff0c\u8acb\u78ba\u4fdd\u958b\u653e HTTP \u548c HTTPS \u7aef\u53e3\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u958b\u653e 80 \u548c 443 \u7aef\u53e3\uff1a<\/p>\n<pre><code>sudo ufw allow 'Nginx Full'<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-VodnhiPjOL\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e0b\u7de8\u8b6f\u5b89\u88dd Nginx\uff0c\u4e26\u9032\u884c\u57fa\u672c\u7684\u914d\u7f6e\u548c\u9632\u706b\u7246\u8a2d\u7f6e\u3002\u9019\u4e9b\u6b65\u9a5f\u5c07\u5e6b\u52a9\u60a8\u5728\u81ea\u5df1\u7684\u4f3a\u670d\u5668\u4e0a\u904b\u884c Nginx\uff0c\u63d0\u4f9b\u9ad8\u6548\u7684\u7db2\u9801\u670d\u52d9\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u7db2\u7ad9\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu \u4e0a\u7de8\u8b6f\u5b89\u88dd Nginx\uff0c\u4e26\u9032\u884c\u76f8\u95dc\u8a2d\u7f6e\uff0c\u63d0\u5347\u4f3a\u670d\u5668\u6027\u80fd\u8207\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-52277","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=52277"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52277\/revisions"}],"predecessor-version":[{"id":52278,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52277\/revisions\/52278"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=52277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=52277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=52277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}