将域名添加到Debian服务器的最简单方法是什么?

时间:2013-11-27 12:05:54

标签: apache debian

我有最新的Debian服务器。该网站应仅托管1个单一域名。 DNS由注册商解决,A指向我的专用服务器。网站位于/var/www/

配置Apache以添加此域名的最简单方法(步骤)是什么?

1 个答案:

答案 0 :(得分:0)

应该非常简单:

  1. 安装Apache(sudo aptitude install apache2
  2. 默认配置指向/ var / www so ...
  3. 启动Apache(sudo service apache2 restart
  4. 享受您的网站
  5. 您可以将您的域名添加到/etc/hosts
  6. 采取一些措施保护您的专用服务器(iptables,fail2ban,...)
  7. 您也可以将自动向导与sudo dpkg-reconfigure apache2一起使用。

    如果您的DNS已经指向您的IP,我认为这应该足够了。

    如果您确实需要更改配置文件,它位于etc/apache2/sites-available/default并包含以下内容(默认情况下):

    NameVirtualHost *
    <VirtualHost *>
    ServerAdmin webmaster@localhost  # <= Email of webadmin (shown on error pages)
    
    DocumentRoot /var/www/           # <= Root of your web server with public access
    <Directory />
        Options FollowSymLinks
        AllowOverride None       # <= Disable usage of .htaccess files
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
    </Directory>
    
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>
    
    ErrorLog /var/log/apache2/error.log
    
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    
    CustomLog /var/log/apache2/access.log combined
    ServerSignature On
    
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
    
    </VirtualHost>
    

    对于hosts文件,您可以添加以下内容:

    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1       localhost
    
    #Virtual Hosts 
    12.34.56.789    example.com #<= change here :)
    

    然后,不要忘记使用适当的工具(iptables,fail2ban,...)保护您的Web服务器