配置本地开发环境,为 wp dev 指定别名

配置本地开发环境,为 wp dev 指定别名

我知道人们已经重复说过一千遍了,但是当我输入我的域名时,我就是无法让我的浏览器解析为 127.0.0.1。

我正在本地开发一个 WP 网站。输入 localhost 可以正常访问该网站,但输入域名时,它无法解析到 localhost。

有人能帮助我吗?

在 /etc/hosts 中:

127.0.0.1 localhost thewriters.ink

/etc/apache2/apache2.conf:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

/etc/apache2/sites-available/thewriterink.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
        ServerName thewriters.ink
        ServerAlias thewriters.ink
        ServerAdmin [email protected]

    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log com
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我之所以尝试这样做是因为我希望网站内的链接http://thewriters.ink并且插件可以使用该 URL,这样当其上传到生产服务器时,我就不必返回并手动更改数十个链接。

(我已使用 a2dissite 和 a2ensite 禁用 000-default.conf 并启用 thewritersink.conf。)

感谢大家的帮助
。Robot876

答案1

您可以尝试几种方法来按您希望的方式解析域名。

记住 IPv6/etc/hosts

尝试这个:

127.0.0.1       localhost
127.0.0.1       thewriters.ink

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

::1     thewriters.ink

笔记:虽然您可以在一行中列出多个域,但我发现通过将每个域放在具有相同 IP 地址的单独行中,可以在各个发行版中提供更好的支持。

删除重复的行并将 catch-all 添加到您的 Apache 虚拟主机配置中:

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        ServerName thewriters.ink
        ServerAlias *.thewriters.ink
        DirectoryIndex index.php index.html
        EnableMMAP Off

        <Directory /var/www/html>
                Options FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/thewriters-error.log
        CustomLog ${APACHE_LOG_DIR}/thewriters-access.log combined
</VirtualHost>

现在您应该能够重新启动 Apache 并让一切“正常工作”...只要启用了 Apache 配置文件:

sudo service apache2 restart

相关内容