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

在本文中,我们将学习如何移动或更改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默认文档根文件夹位置更改为另一个卷上安装的新位置,我们希望在该位置上管理单个服务器上的站点和批量站点日期。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值