如何在 ubuntu 上使用 apache 正确设置网站和域(带子域)? [英] How properly set a website and domain (with subdomains) with apache on ubuntu?

查看:36
本文介绍了如何在 ubuntu 上使用 apache 正确设置网站和域(带子域)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,为我的英语道歉.

First of all, apologies for my English.

上周我一直在阅读和阅读指南,但没有成功.我买了一个域 + 托管,但由于性能不佳,我有一个便宜的 vps 用作托管.目前我的设置是:

I've been reading and reading guides last week a lot hours with no success. I bought a domain + hosting but due bad performance I've got a cheap vps to use as hosting. Currently my setup is:

  • 一个带有 A 记录的域名 .com 指向我的 vps ip.
  • 使用 Ubuntu 14.04.2 64 位的非托管 vps 用作我的 wordpress 的主机,默认设置为 LAMP 堆栈(我没有更改 apache 上的任何设置,使用默认虚拟主机).
  • A domain .com with an A record pointed to my vps ip.
  • A unmanaged vps with Ubuntu 14.04.2 64 bits to use as hosting for my wordpress with LAMP stack with default setup (I didn't changed any setting on apache, using default virtualhost).

我的网站运行良好,但我不知道如何使用不同的目录创建子域.例如,我的 website.com 文件位于/var/www/html 中,我想使用其他目录中的文件创建 subdomain.website.com,假设为/var/www/subdomain.

My site works fine but I'm don't know how create subdomains with different directories. For example, my website.com files are in /var/www/html and I'd like to create subdomain.website.com with the files in other directory, let's say /var/www/subdomain.

我查了很多教程,他们说要在 apache 上创建一个虚拟服务器(我使用 webmin),然后是指向服务器 ip 的子域的 A 记录.

I checked a lot tutorials and they say to create a virtual server on apache (I use webmin) and then an A record for the subdomain pointing to the server ip.

问题是,当我进入 subdomain.website.com 时,我看到了来自主域的内容 (/var/www/html) 而不是来自/var/www/子域"

The problem is that when I enter to subdomain.website.com I see the content from main domain (/var/www/html) and not from "/var/www/subdomain"

我不想一步一步地向您询问完整的指南,我只需要知道我需要从哪里开始实现具有不同目录的子域,因为通常我总是使用带有 cpanel 等工具的托管服务来创建指向的子域点击 2 次即可访问目录.

I don't want ask you for a full guide step by step, I just need know where I need to start for achieve a subdomain with a different directory because usually I always used hosting services with tools like cpanel to create subdomains pointed to directories in 2 clicks.

我是 Apache/dns 管理的新手.

I'm a full newbie with Apache/dns management.

非常感谢您的时间!

推荐答案

通过在 /etc/apache2/sites-available/subdomain.website.com.conf 中创建一个文件,在 Apache 中创建一个虚拟主机

在该文件中,添加以下内容

In that file, add the following

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName subdomain.website.com
    DocumentRoot /var/www/subdomain.website.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

现在将您的 subdomain.website.com 文件放在

Now place your subdomain.website.com files at

/var/www/subdomain.website.com/public_html

然后通过 sudo a2ensite subdomain.website.com

放置文件后,如果出现 403 禁止错误,请检查 DocumentRoot 文件夹的权限.

After placing the files, if you get a 403 forbidden error, check for permissions of the DocumentRoot folder.

参考:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

这篇关于如何在 ubuntu 上使用 apache 正确设置网站和域(带子域)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆