在本文中,我们将学习如何移动或更改Nginx Web服务器文件文件夹的位置。默认情况下,Nginx Web服务器的默认位置为/ usr / share / nginx / html,位于Linux的默认文件系统上。通常,这是根据网站要求或客户要求完成的。

先决条件要完成我们的设置,我们需要以下要求。

已在计算机上安装具有sudo权限的Ubuntu 16.04。

已安装Nginx Web服务器

我们要更改默认文档位置的已安装驱动器或新文档。

将文档根文件复制到新位置

由于Nginx的默认文档根目录位于/ usr / share / nginx / html,因此,如果您已安装Nginx并配置了现有服务器,我们需要检查/ etc / nginx / sites-enabled上启用了站点的文件夹,如果在现有服务器上更改了位置,则可以使用以下命令搜索启用了sites的文件夹$ grep “root” –R /etc/nginx/sites-enabled

/etc/nginx/sites-enabled/default: root /usr/share/nginx/html;

/etc/nginx/sites-enabled/default: # deny access to .htaccess files, if Apache's document root

/etc/nginx/sites-enabled/default:# root /var/www/demosite;

将站点数据移动到新位置

假设我们将默认站点文件/ var / www / demosite移至新创建的卷,该卷位于/ mnt / newdatavolume。$ sudo rsync –av /usr/share/nginx/html /mnt/newdatavolume

更改Nginx的配置文件

Nginx允许我们更改全局站点或特定站点的配置,在此演示中,我们使用的是将现有站点从默认位置更改为新位置,我们必须使用grep命令查找位置并更改配置文件。$ sudo vi /etc/nginx/sites-enabled/000-default

我们需要寻找“ root”行并更新该行的新位置注释并添加新行root /mnt/newdatavolume

以下是默认nginx配置的示例文件。##

# You should look at the following URL's in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# http://wiki.nginx.org/Pitfalls

# http://wiki.nginx.org/QuickStart

# http://wiki.nginx.org/Configuration

#

# Generally, you will want to move this file somewhere, and start with a clean

# file but keep this around for reference. Or just disable in sites-enabled.

#

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

#root /usr/share/nginx/html;

root /mnt/newdatavolume

index index.html index.htm;

# Make site accessible from http://localhost/

server_name localhost;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

try_files $uri $uri/ =404;

# Uncomment to enable naxsi on this location

# include /etc/nginx/naxsi.rules

}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests

#location /RequestDenied {

# proxy_pass http://127.0.0.1:8080;

#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

重新启动Nginx Web服务器

更改配置后,相应地,我们需要重新启动Nginx Web服务器以应用更改。首先,我们将检查配置文件并重新启动Niginx Web服务器。$ sudo nginx –t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

$ sudo systemctl restart nginx在上面的文章和设置中,我们学习了将Nginx默认文档根文件夹位置更改为另一个卷上安装的新位置,我们希望在该位置上管理单个服务器上的站点和批量站点日期。

ubuntu nginx html文件,如何在Ubuntu 16.04上更改Nginx Web文档位置相关推荐

  1. 如何保护Ubuntu 16.04上的NGINX Web服务器

    什么是 Let's Encrypt Let's Encrypt 是互联网安全研究组织 (ISRG) 提供的免费证书认证机构.它提供了一种轻松自动的方式来获取免费的 SSL/TLS 证书 - 这是在 W ...

  2. ubuntu下mysql5.7安装教程_Ubuntu 16.04 上安装 MySQL 5.7 教程

    介绍 MySQL 是一种开源数据库管理系统,通常作为流行的LAMP(Linux,Apache,MySQL,PHP / Python / Perl)堆栈的一部分安装.它使用关系数据库和SQL(结构化查询 ...

  3. 如何在 ubuntu 16.04上运行jar文件

    如何在 ubuntu 16.04上运行jar文件 sudo apt-get update 1 安装依赖包 sudo apt-get install python-software-properties ...

  4. 如何在Ubuntu 18.04上使用Nginx与MySQL服务器一起部署ASP.NET Core应用程序

    The author selected the Open Source Initiative to receive a donation as part of the Write for DOnati ...

  5. 如何在Ubuntu 16.04上使用MySQL 5.6配置Galera集群

    原作者:梅丽莎安德森  转载翻译:https://www.digitalocean.com/community/tutorials/how-to-configure-a-galera-cluster- ...

  6. 如何在Ubuntu 16.04上创建多节点MySQL集群(MySQL-Cluster)

    翻译转载:https://www.digitalocean.com/community/tutorials/how-to-create-a-multi-node-mysql-cluster-on-ub ...

  7. 如何在Ubuntu 16.04上使用ProxySQL缓存优化MySQL查询

    The author selected the Free Software Foundation to receive a donation as part of the Write for DOna ...

  8. 【转】如何在Ubuntu 16.04上使用UFW设置防火墙

    https://www.howtoing.com/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04/ 如何在Ubuntu 16.04上使用UFW设置防 ...

  9. 如何在Ubuntu 16.04上增加Swap分区

    最近在安装一些软件的时候经常出现因为内存不足而崩溃的错误,故查看了Linux Swap分区的介绍,以及如何创建swap分区.内容转自下面两篇优质文章.谢谢这两位作者的整理与无私奉献.读者可直接点击链接 ...

最新文章

  1. Win10下使用Debug
  2. STM32开发 -- 4G模块开发详解(4)
  3. cad导出pdf_通过CAD导出的文件或者由CAD导出的PDF文件打印慢
  4. Delphi DLL制作和加载 Static, Dynamic, Delayed 以及 Shared-Memory Manager
  5. 百度android广告sdk下载,IS_Freedom
  6. 电脑w ndows无法自动修复,windows 10自动修复无法修复你的电脑
  7. 移植U-BOOT之裁剪和修改默认参数(易用性)启动内核,以及对uboot进行分区
  8. mini2440驱动分析之LCD
  9. noip2004普及组第2题 花生采摘
  10. Java实现的日历(原创)
  11. String 和 InputStream 互转方式
  12. java jettison_java – 使用Jettison进行JSON解析
  13. 《机器人编程实战》一一2.1 为什么需要更多努力
  14. DarkAngels勒索病毒分析
  15. 屏幕坏了无法使用计算机调试,vivo手机屏幕坏了连接电脑没反应怎么办
  16. 51单片机无法烧录程序的N种解决办法
  17. windows PE文件结构及其加载机制
  18. Unity 四种截图方法(相机视图、无UI、有UI、Game窗口)
  19. 重心在哪里(简单数学题)
  20. 微信小程序之沉浸式导航

热门文章

  1. python爬虫可以爬什么山好_Python爬虫示例:爬取 13 个旅游城市,看看大家放假了都爱去哪玩...
  2. 蓝桥杯 2014 C++B(5) Log大侠 线段树 区间修改
  3. 学习poi导出excel之XSSFWorkbook
  4. Ubuntu连接不了网络的解决方法(第二种亲测可行)
  5. 上传文件时让弹窗显示指定格式的文件
  6. 网页标签对网站排名的影响
  7. 为什么TCP握手是三次握手而不是两次
  8. coredns 更新部署
  9. 视觉SLAM⑥---非线性优化
  10. c++做一个计算两向量夹角的程序