[{"data":1,"prerenderedAt":237},["ShallowReactive",2],{"content:\u002Fposts\u002F2022\u002Fnginx-install-and-setup":3,"surround:\u002Fposts\u002F2022\u002Fnginx-install-and-setup":226},{"id":4,"title":5,"body":6,"canonical":204,"categories":205,"date":207,"description":208,"draft":209,"extension":210,"image":211,"meta":212,"navigation":213,"path":214,"permalink":204,"readingTime":215,"recommend":204,"references":204,"seo":220,"sitemap":221,"stem":222,"tags":223,"type":204,"updated":207,"__hash__":225},"content\u002Fposts\u002F2022\u002FNginx-install-and-setup.md","Nginx安装配置",{"type":7,"value":8,"toc":189},"minimark",[9,13,20,25,36,39,45,49,56,62,67,73,78,84,88,92,118,121,128,133,136,144,157,163,166,170,176,179],[10,11,12],"h1",{"id":12},"nginx",[14,15,16],"blockquote",{},[17,18,19],"p",{},"在这里我服务器使用的 ubuntu 的系统，所以就用它举例。其他操作系统几乎一致。",[21,22,24],"h2",{"id":23},"在-ubuntu-中安装-nginx","在 ubuntu 中安装 nginx",[26,27,33],"pre",{"className":28,"code":30,"language":31,"meta":32},[29],"language-shell","sudo apt update\nsudo apt install nginx\n","shell","",[34,35,30],"code",{"__ignoreMap":32},[17,37,38],{},"安转完成 nginx 会自动启用，您可以在浏览器中输入您的 ip 进行查看（需要确认您的服务防火墙开启了 80 端口）。或者使用命令",[26,40,43],{"className":41,"code":42,"language":31,"meta":32},[29],"sudo systemctl status nginx\n",[34,44,42],{"__ignoreMap":32},[21,46,48],{"id":47},"nginx-常用命令","nginx 常用命令",[50,51,52],"ul",{},[53,54,55],"li",{},"启动 nginx 服务",[26,57,60],{"className":58,"code":59,"language":31,"meta":32},[29],"sudo nginx -s start\n",[34,61,59],{"__ignoreMap":32},[50,63,64],{},[53,65,66],{},"停止 nginx 服务",[26,68,71],{"className":69,"code":70,"language":31,"meta":32},[29],"sudo nginx -s stop\n",[34,72,70],{"__ignoreMap":32},[50,74,75],{},[53,76,77],{},"重启 nginx 服务",[26,79,82],{"className":80,"code":81,"language":31,"meta":32},[29],"sudo nginx -s reload\n",[34,83,81],{"__ignoreMap":32},[21,85,87],{"id":86},"nginx-配置","nginx 配置",[89,90,91],"h3",{"id":91},"配置文件详情",[50,93,94,101,107],{},[53,95,96,97,100],{},"默认的配置文件在 ",[34,98,99],{"code":99},"\u002Fetc\u002Fnginx\u002F","目录下",[53,102,103,104],{},"主要的配置文件是 ",[34,105,106],{"code":106},"\u002Fetc\u002Fnginx\u002Fnginx.conf",[53,108,109,110,113,114,117],{},"Nginx 服务器配置文件被储存在 ",[34,111,112],{"code":112},"\u002Fetc\u002Fnginx\u002Fsites-available"," 目录下。在 ",[34,115,116],{"code":116},"\u002Fetc\u002Fnginx\u002Fsites-enabled"," 目录下的配置文件都将被 Nginx 使用。",[89,119,120],{"id":120},"自定义配置",[17,122,123,124,127],{},"我们可以使用 ",[34,125,126],{"code":126},"sudo vim \u002Fetc\u002Fnginx\u002Fsites-enabled\u002Fdefault"," 来查看和修改 nginx 配置文件",[14,129,130],{},[17,131,132],{},"这里使用 sudo 是为了避免遭遇权限问题导致文件保存报错",[17,134,135],{},"下面是主要要修改的配置",[26,137,142],{"className":138,"code":140,"language":141,"meta":32},[139],"language-text","server {\n  listen 80;\n  listen [::]:80;\n\n  server_name example.com;\n\n  root \u002Fvar\u002Fwww\u002Fexample.com;\n  index index.html;\n\n  location \u002F {\n    try_files $uri $uri\u002F =404;\n  }\n}\n","text",[34,143,140],{"__ignoreMap":32},[145,146,148,149,152,153,156],"h4",{"id":147},"我们可以在-location-这个模块下-新建一个-root-来指定我们要访问的跟路径","我们可以在 ",[34,150,151],{"code":151},"location"," 这个模块下 新建一个 ",[34,154,155],{"code":155},"root"," 来指定我们要访问的跟路径",[26,158,161],{"className":159,"code":160,"language":141},[139],"location \u002F {\n  root \u002Fcode\u002Fvitepress\u002Fdist;\n}\n",[34,162,160],{"__ignoreMap":32},[17,164,165],{},"如果该项目和默认配置的 root 地址不是一个，需要在 location 模块中配置对应的 root 目录，不然网站的 css 或者其他文件会加载不到",[145,167,169],{"id":168},"我们可以设置-index-来设置默认访问文件","我们可以设置 index 来设置默认访问文件",[26,171,174],{"className":172,"code":173,"language":141},[139],"location \u002F {\n  index index.html;\n}\n",[34,175,173],{"__ignoreMap":32},[17,177,178],{},"这里的 index.html 会自动拼接上面设置的 root 路径，如果在 location 中没有配置 root 就会使用全局的 server 下的 root 路径",[180,181,182],"alert",{},[17,183,184,185,188],{},"记得每行命令结束后加上 ",[34,186,187],{"code":187},";","， 要不然会报错的",{"title":32,"searchDepth":190,"depth":190,"links":191},4,[192,194,195],{"id":23,"depth":193,"text":24},2,{"id":47,"depth":193,"text":48},{"id":86,"depth":193,"text":87,"children":196},[197,199],{"id":91,"depth":198,"text":91},3,{"id":120,"depth":198,"text":120,"children":200},[201,203],{"id":147,"depth":190,"text":202},"我们可以在 location 这个模块下 新建一个 root 来指定我们要访问的跟路径",{"id":168,"depth":190,"text":169},null,[206],"代码","2022-12-04 13:27:32","ubuntu 系统中 Nginx 的简易安装和配置",false,"md","https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F679f16a24d380-78.webp",{},true,"\u002Fposts\u002F2022\u002Fnginx-install-and-setup",{"text":216,"minutes":217,"time":218,"words":219},"3 min read",2.13,127800,426,{"title":5,"description":208},{"loc":214},"posts\u002F2022\u002FNginx-install-and-setup",[224],"Nginx","EHzIrh7ThpcCJdHin6CkYLlFcoSRUVwRObh-Ne0q1fk",[227,232],{"title":228,"path":229,"stem":230,"date":231,"type":204,"children":-1},"Nginx gzip配置","\u002Fposts\u002F2022\u002Fnginx-gzip","posts\u002F2022\u002Fnginx-gzip","2022-12-03 12:00:00",{"title":233,"path":234,"stem":235,"date":236,"type":204,"children":-1},"uni-app app打包上线要注意的部分","\u002Fposts\u002F2022\u002Fminiprogram-app-build","posts\u002F2022\u002Fminiprogram-app-build","2022-12-04 15:17:52",1789642597518]