点域到IP

发布于 2025-02-12 17:29:12 字数 706 浏览 0 评论 0原文

我在CentOS上创建了Apache服务器,并配置了整个环境。我已经完成了将IP指向域的部分,甚至激活了SSL证书(让我们加密),并且有效,但是有些事情出了问题。例如,当我单击域上的屏幕上的任何链接时,URL会自动转到我的IP,而不是继续域。当我尝试访问domain.com/wp-admin时,也会发生同样的情况,将其重定向到IP/WP-ADMIN。我认为这是一些基本的配置,但我在这部分中是初学者,因此,如果有人能提供帮助,我将不胜感激!

vhosts:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/html/wordpress
    ErrorLog /var/www/example.com/log/error.log
    CustomLog /var/www/example.com/log/requests.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I created an apache server on Centos and configured the entire environment. I've already done the part of pointing the IP to the domain and even activated the SSL certificate (Lets Encrypt) and it worked, but some things are going wrong. For example, when I click on any link on the screen on my domain, the URL automatically goes to my IP instead of continuing on the domain. The same happens when I try to access domain.com/wp-admin, it is redirected to IP/wp-admin. I think it's some basic configuration but I'm a beginner in this part so if anyone can help I'll be grateful!

Vhosts:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/html/wordpress
    ErrorLog /var/www/example.com/log/error.log
    CustomLog /var/www/example.com/log/requests.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人的歌 2025-02-19 17:29:12

对于默认的conf文件(将所有请求重定向到您的域中):

<VirtualHost IP_ADDRESS:80>
        Protocols h2 h2c http/1.1
        ServerAdmin [email protected]
        Redirect permanent / https://example.com/

        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

对于您的域conf文件:

<VirtualHost example.com:80>
        Protocols h2 http/1.1
        RewriteEngine on
        ServerName example.com
        Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost example.com:443>
        Protocols h2 h2c http/1.1
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

        ServerName example.com

        DocumentRoot /var/www/example.com

        Alias / "/var/www/example.com/"
        <Directory /var/www/example.com/>
                Require all granted
                AllowOverride All
                Options FollowSymLinks MultiViews

                <IfModule mod_dav.c>
                        Dav off
                </IfModule>
        </Directory>
        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
        </IfModule>
</VirtualHost>

for default conf file (redirects all request to your domain with https):

<VirtualHost IP_ADDRESS:80>
        Protocols h2 h2c http/1.1
        ServerAdmin [email protected]
        Redirect permanent / https://example.com/

        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And for your domain conf file:

<VirtualHost example.com:80>
        Protocols h2 http/1.1
        RewriteEngine on
        ServerName example.com
        Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost example.com:443>
        Protocols h2 h2c http/1.1
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

        ServerName example.com

        DocumentRoot /var/www/example.com

        Alias / "/var/www/example.com/"
        <Directory /var/www/example.com/>
                Require all granted
                AllowOverride All
                Options FollowSymLinks MultiViews

                <IfModule mod_dav.c>
                        Dav off
                </IfModule>
        </Directory>
        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
        </IfModule>
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文