{"id":45052,"date":"2024-10-06T20:06:14","date_gmt":"2024-10-06T12:06:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45052\/"},"modified":"2024-10-06T20:06:14","modified_gmt":"2024-10-06T12:06:14","slug":"ubuntu-centos-%e7%b3%bb%e7%b5%b1%e4%b8%8a%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae-nginx","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45052\/","title":{"rendered":"Ubuntu\/CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Nginx"},"content":{"rendered":"<h1 id=\"ubuntu-centos-%e7%b3%bb%e7%b5%b1%e4%b8%8a%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae-nginx-BzCuLydUjg\">Ubuntu\/CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Nginx<\/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\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u61c9\u7528\uff0cNginx \u90fd\u80fd\u63d0\u4f9b\u5353\u8d8a\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Nginx\u3002<\/p>\n<h2 id=\"%e5%9c%a8-ubuntu-%e4%b8%8a%e5%ae%89%e8%a3%9d-nginx-BzCuLydUjg\">\u5728 Ubuntu \u4e0a\u5b89\u88dd Nginx<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1-%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-BzCuLydUjg\">\u6b65\u9a5f 1: \u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2-%e5%ae%89%e8%a3%9d-nginx-BzCuLydUjg\">\u6b65\u9a5f 2: \u5b89\u88dd Nginx<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Nginx\uff1a<\/p>\n<pre><code>sudo apt install nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3-%e5%95%9f%e5%8b%95-nginx-BzCuLydUjg\">\u6b65\u9a5f 3: \u555f\u52d5 Nginx<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 Nginx \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4-%e8%a8%ad%e5%ae%9a%e9%96%8b%e6%a9%9f%e5%95%9f%e5%8b%95-BzCuLydUjg\">\u6b65\u9a5f 4: \u8a2d\u5b9a\u958b\u6a5f\u555f\u52d5<\/h3>\n<p>\u70ba\u4e86\u78ba\u4fdd Nginx \u5728\u7cfb\u7d71\u91cd\u555f\u5f8c\u81ea\u52d5\u555f\u52d5\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-5-%e9%a9%97%e8%ad%89%e5%ae%89%e8%a3%9d-BzCuLydUjg\">\u6b65\u9a5f 5: \u9a57\u8b49\u5b89\u88dd<\/h3>\n<p>\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\uff0c\u82e5\u770b\u5230 Nginx \u7684\u6b61\u8fce\u9801\u9762\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e5%9c%a8-centos-%e4%b8%8a%e5%ae%89%e8%a3%9d-nginx-BzCuLydUjg\">\u5728 CentOS \u4e0a\u5b89\u88dd Nginx<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1-%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-BzCuLydUjg\">\u6b65\u9a5f 1: \u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo yum update<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2-%e5%ae%89%e8%a3%9d-epel-%e5%80%89%e5%ba%ab-BzCuLydUjg\">\u6b65\u9a5f 2: \u5b89\u88dd EPEL \u5009\u5eab<\/h3>\n<p>Nginx \u5728 CentOS \u7684\u9810\u8a2d\u5009\u5eab\u4e2d\u4e26\u4e0d\u5b58\u5728\uff0c\u56e0\u6b64\u9700\u8981\u5b89\u88dd EPEL \u5009\u5eab\uff1a<\/p>\n<pre><code>sudo yum install epel-release<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3-%e5%ae%89%e8%a3%9d-nginx-BzCuLydUjg\">\u6b65\u9a5f 3: \u5b89\u88dd Nginx<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Nginx\uff1a<\/p>\n<pre><code>sudo yum install nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4-%e5%95%9f%e5%8b%95-nginx-BzCuLydUjg\">\u6b65\u9a5f 4: \u555f\u52d5 Nginx<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 Nginx \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-5-%e8%a8%ad%e5%ae%9a%e9%96%8b%e6%a9%9f%e5%95%9f%e5%8b%95-BzCuLydUjg\">\u6b65\u9a5f 5: \u8a2d\u5b9a\u958b\u6a5f\u555f\u52d5<\/h3>\n<p>\u70ba\u4e86\u78ba\u4fdd Nginx \u5728\u7cfb\u7d71\u91cd\u555f\u5f8c\u81ea\u52d5\u555f\u52d5\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable nginx<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-6-%e9%a9%97%e8%ad%89%e5%ae%89%e8%a3%9d-BzCuLydUjg\">\u6b65\u9a5f 6: \u9a57\u8b49\u5b89\u88dd<\/h3>\n<p>\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\uff0c\u82e5\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-BzCuLydUjg\">\u914d\u7f6e Nginx<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u6839\u64da\u9700\u6c42\u914d\u7f6e Nginx\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u914d\u7f6e\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1-%e7%b7%a8%e8%bc%af%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-BzCuLydUjg\">\u6b65\u9a5f 1: \u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>Nginx \u7684\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\u4f4d\u65bc \/etc\/nginx\/nginx.conf\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6253\u958b\u8a72\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2-%e8%a8%ad%e5%ae%9a%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%8d%80%e5%a1%8a-BzCuLydUjg\">\u6b65\u9a5f 2: \u8a2d\u5b9a\u4f3a\u670d\u5668\u5340\u584a<\/h3>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6dfb\u52a0\u4f3a\u670d\u5668\u5340\u584a\u4f86\u8a2d\u5b9a\u4e0d\u540c\u7684\u7db2\u7ad9\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n    \n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n}<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3-%e6%b8%ac%e8%a9%a6%e9%85%8d%e7%bd%ae-BzCuLydUjg\">\u6b65\u9a5f 3: \u6e2c\u8a66\u914d\u7f6e<\/h3>\n<p>\u5728\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e2c\u8a66\u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4-%e9%87%8d%e6%96%b0%e5%95%9f%e5%8b%95-nginx-BzCuLydUjg\">\u6b65\u9a5f 4: \u91cd\u65b0\u555f\u52d5 Nginx<\/h3>\n<p>\u82e5\u914d\u7f6e\u6b63\u78ba\uff0c\u5247\u91cd\u65b0\u555f\u52d5 Nginx \u4ee5\u61c9\u7528\u66f4\u6539\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BzCuLydUjg\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Nginx\u3002\u7121\u8ad6\u60a8\u662f\u65b0\u624b\u9084\u662f\u6709\u7d93\u9a57\u7684\u4f7f\u7528\u8005\uff0c\u9019\u4e9b\u6b65\u9a5f\u90fd\u80fd\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b Nginx\u3002\u82e5\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\uff0c\u8b93\u60a8\u7684\u7db2\u7ad9\u904b\u884c\u66f4\u52a0\u6d41\u66a2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu \u548c CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd\u8207\u914d\u7f6e Nginx\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u5b89\u5168\u6027\uff0c\u7c21\u55ae\u6613\u61c2\u7684\u6b65\u9a5f\u6307\u5357\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-45052","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45052","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=45052"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45052\/revisions"}],"predecessor-version":[{"id":45053,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45052\/revisions\/45053"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}