AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[301-redirect](server)

Martin Hope
Patryk Chowratowicz 'Zszywacz'
Asked: 2022-01-27 09:19:54 +0800 CST

如何仅使用 DNS 记录将域 A 重定向到域 B 而无需托管?

  • 2

我想重定向domain A(没有托管空间)到domain B(301),但是当我尝试https://domainA.com或https://www.domainA.com时,它以ERR_CONNECTION_REFUSED. 甚至可以只使用 DNS 记录吗?

我正在使用 OVH.com 重定向面板,并且 http:// 重定向工作正常。

hosting https ovh 301-redirect redirection
  • 4 个回答
  • 556 Views
Martin Hope
Pc Monk
Asked: 2022-01-24 22:07:34 +0800 CST

Nginx http 到 https 重定向下载空文件

  • 0

我试图将我的Laravel+vuejs+nuxtjs项目从http重定向到https,但是当我输入http://example.com或http://www.example.com时,会下载一个空文件

到目前为止我做了什么:

1-在 nginx.conf 中default_type application/octet-stream添加注释和default_type text/html代替

2-定义types { } default_type "text/plain";example.com.conflocation /{}

3-nginx 使用下面的代码重定向

server{
  listen xx.xx.xx.xx:80;
    server_name example.com www.example.com;
  return 301 https://www.example.com$request_uri;
}

4-尝试使用带有以下 example.com.conf 文件的 .php 文件重定向它:

       server {
          listen 37.152.191.249:80;
          server_name www.example.com example.com;

         access_log /usr/local/apache/domlogs/example.com.bytes bytes;
        access_log /usr/local/apache/domlogs/example.com.log combined;
        error_log /usr/local/apache/domlogs/example.com.error.log error;

        root /home/example/public_html/;
        index index.php;

   location / {
types { } default_type "text/plain";
    try_files                       $uri $uri/  /index.php?$query_string;

}

location ~ \.php$ {
   fastcgi_split_path_info         ^(.+\.php)(/.+)$;
    fastcgi_pass                    127.0.0.1:9000;
    fastcgi_index                   index.php;
    include                         fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_intercept_errors        off;
    fastcgi_buffer_size             16k;
    fastcgi_buffers                 4 16k;
    fastcgi_connect_timeout         300;
   fastcgi_send_timeout            300;
    fastcgi_read_timeout            300;
}


        location ~* "/\.(htaccess|htpasswd)$" {deny all;return 404;}

        disable_symlinks if_not_owner from=/home/example/public_html;
}

public_html 代码中的 index.php :

    $location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $location);
    exit;

以上都没有奏效,问题仍然存在。

+当前配置:

nginx -t 报告:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

example.com.ssl.conf:

server{
  listen xx.xx.xx.xx:443 http2 ssl;
    server_name example.com;
        ssl_certificate      /etc/pki/tls/certs/example.com.bundle;
        ssl_certificate_key  /etc/pki/tls/private/example.com.key;
        ssl_protocols TLSv1.2;
        ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EE3CDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA!RC4:EECDH:!RC4:!aNULL:!eN$
        ssl_prefer_server_ciphers   on;

       ssl_session_cache   shared:SSL:10m;
       ssl_session_timeout 60m;
       return 301 https://www.example.com$request_uri;
}
       server {
          listen xx.xx.xx.xx:443 http2 ssl;
          server_name www.example.com;

         access_log /usr/local/apache/domlogs/example.com.bytes bytes;
        access_log /usr/local/apache/domlogs/example.com.log combined;
        error_log /usr/local/apache/domlogs/example.com.error.log error;
        ssl_certificate      /etc/pki/tls/certs/example.com.bundle;
        ssl_certificate_key  /etc/pki/tls/private/example.com.key;
        ssl_protocols TLSv1.2;
        ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA!RC4:EECDH:!RC4:!aNULL:!eN$
        ssl_prefer_server_ciphers   on;

        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 60m;

        root /home/example/core/public/;
        index index.php;

   location / {
  proxy_set_header                Connection 'upgrade';
    proxy_http_version              1.1;
    proxy_pass                      https://xx.xx.xx.xx:3000$uri;
    proxy_intercept_errors          on;# In order to use error_page directive this needs to be on
    error_page                      404 = @php;
}

location @php {
    try_files                       $uri $uri/  /index.php?$query_string;

}

location ~ \.php$ {
   fastcgi_split_path_info         ^(.+\.php)(/.+)$;
    fastcgi_pass                    127.0.0.1:9000;
    fastcgi_index                   index.php;
    include                         fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   fastcgi_intercept_errors        off;
    fastcgi_buffer_size             16k;
    fastcgi_buffers                 4 16k;
    fastcgi_connect_timeout         300;
   fastcgi_send_timeout            300;
    fastcgi_read_timeout            300;
}


        location ~* "/\.(htaccess|htpasswd)$" {deny all;return 404;}

        disable_symlinks if_not_owner from=/home/example/public_html;

        location /.well-known/acme-challenge {
                default_type "text/plain";
                alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
        }

        location /.well-known/pki-validation {
                default_type "text/plain";
                alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
        }
}


当前 example.com.conf:

server{
  listen xx.xx.xx.xx:80;
    server_name example.com www.example.com;
  return 301 https://www.example.com$request_uri;
}

我没有添加 nginx -T 报告,因为它显示了来自其他网站的不相关配置文件。

此外,运行多个站点的服务器和 wordpress 使用在#3处提供的代码进行重定向也没有问题,但是当涉及到使用 nuxtjs 的站点时,我下载了一个空文件。

任何帮助将不胜感激

nginx centos7 301-redirect
  • 1 个回答
  • 274 Views
Martin Hope
ashanrupasinghe
Asked: 2021-11-20 20:58:56 +0800 CST

301重定向某些页面和所有其他页面

  • 0

我有两个网站。让我们说siteA.com和 siteB.com。现在我想将 301 重定向添加到siteB.com. 某些页面siteB.com需要重定向到某些特定页面上的siteA.com 所有其他页面都siteB.com需要重定向到siteA.com包括siteB主页的主页。我的最终要求是添加重定向后没有人可以访问siteB。这是两个 wordpress 网站。如何使用 htaccess 文件或 wordpress 插件完成此操作?

linux .htaccess wordpress 301-redirect shutdown
  • 1 个回答
  • 84 Views
Martin Hope
Samuel
Asked: 2021-08-10 03:04:00 +0800 CST

将法语主页(并且只有 FR 主页)重定向到英语主页

  • 1

使用该.htaccess文件,我想重定向www.example.com/fr/到www.example.com/但不是其他具有/fr/根的法语页面(例如www.example.com/fr/page-name)

我尝试过使用Redirect 301 /fr/ https://example.com/,但这会将所有法语页面重定向到我不想要的英语版本。

有没有解决的办法?

.htaccess 301-redirect mod-alias
  • 1 个回答
  • 55 Views
Martin Hope
jwir3
Asked: 2021-08-06 06:23:01 +0800 CST

nginx 重定向或返回单个位置

  • 2

我正在尝试videos.mydomain.com/kickboxing重定向到 YouTube 链接,以及videos.mydomain.com/classes重定向到不同的YouTube 链接。(这些都是未列出的播放列表,我希望任何有权访问我们网站的人都能自动为他们进行重定向。这是配置它的几个步骤的第 1 步,我似乎无法让它工作)。

这是我的配置:

server {
  server_name videos.mydomain.com;
  root /var/www/www.mydomain.com;

  listen 80;
  access_log /var/log/nginx/videos.mydomain.com-access.log;
  error_log /var/log/nginx/videos.mydomain.com-error.log debug;

  location /classes {
    return 301 https://youtube.com/playlist?list=classes-playlist;
  }

  location /kickboxing {
    return 301 https://youtube.com/playlist?list=kickboxing-playlist;
  }

  return 404;
}

我已经在我的可用站点中设置了它,并启用了它(当然,设置了 DNS)。不幸的是,当我导航到网址http://videos.mydomain.com/kickboxing或http://videos.mydomain.com/classes时,我得到的只是 404 网址。如果我将该return 404行更改为其中return 301一行,那么它将适当地重定向,但仅适用于该特定 url。似乎没有正确识别这些location部分。

configuration nginx 301-redirect
  • 1 个回答
  • 100 Views
Martin Hope
thran
Asked: 2021-08-04 13:40:58 +0800 CST

Nginx 在使用多个服务器块时将浏览器置于重定向循环中

  • 0

我正在使用 Nginx 来托管许多虚拟主机(或Nginx 命名法中的服务器块)。这些主机都共享同一个域,每个都分配了自己的子域。一个子域进入一个无限的重定向循环,显然是不受欢迎的行为。

注意:我已经编辑了我的域名并将其替换为<mysite>.

根域 -www.<mysite>.com按预期接收请求。它还将 HTTP 请求重定向到 HTTPS。它配置在<mysite>-www.

子域assets.<mysite>.com也按预期接收请求。它未配置为将 HTTP 重定向到 HTTPS,提供任一协议。没有麻烦。它配置在<mysite>-holding.

最终的子域soft.<mysite>.com配置相同,assets.<mysite>.com但它步履蹒跚。相反,它会在重定向循环中发送浏览器,每次都指向https://soft.<mysite>.comThis is 尽管此 vhost 的配置文件中没有此类设置。它配置在<mysite>-soft.

配置为<mysite>-www:

server {
    server_name www.<mysite>.com;

    listen 80 default_server ;
    listen [::]:80 default_server;

    location / {
        return 301 https://$server_name$request_uri;
    }

    root /var/www/html;
}

server {
    listen              443 ssl default_server;
    ssl_certificate /etc/letsencrypt/live/www.<mysite>.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.<mysite>.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;

    root /var/www/html;
    server_name www.<mysite>.com;
    error_page 404 /404.html;

    location / {
        limit_req zone=mylimit burst=20 nodelay;
        try_files $uri $uri/ =404;
        index index.html index.htm;
    }
}

配置为<mysite>-holding:

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;

    server_name assets.<mysite>.com;

    ssl_certificate /etc/letsencrypt/live/assets.<mysite>.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/assets.<mysite>.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf;

    root /var/www/holding/html;

    location / {
        limit_req zone=mylimit burst=20 nodelay;
        try_files $uri $uri/ =404;
        index index.html;
    }

的配置文件soft.<mysite>.com与上面的相同,除了它说“资产”它说“软”。然而它进入了这个无限的重定向循环。

我试过改变位置指令。我查阅了比预期更好的文档。尽管如此,它还是会循环。帮助将不胜感激!

virtualhost ssl nginx 301-redirect
  • 1 个回答
  • 96 Views
Martin Hope
Minhaj
Asked: 2021-07-23 18:29:49 +0800 CST

用于多级子目录的 Ngnix 重定向

  • 1

我有如下结构的 URL:

xyz/asset.html
abc/test.html
xyz/abc/test.html
xyz/abc/qwerty/test2.html

我想重定向:

xyz/asset.html to xyz/asset

xyz/abc/test.html to xyz/abc/test

xyz/abc/qwerty/test2.html to xyz/abc/qwerty/test2

目前我在我的 ngnix 配置中有这个重定向规则,它适用于第一级目录重定向:

location ~ ^/(xyz|abc).html { return 301 /$1; }

这适用于第一级直接但不适用于子目录。如何做到这一点?谢谢您的帮助。

linux nginx 301-redirect
  • 1 个回答
  • 61 Views
Martin Hope
scaramouche
Asked: 2021-07-10 20:41:47 +0800 CST

让 nginx 将所有内容重定向到 https,除了一个目录

  • 4

我需要 nginx 将所有 http URL 重定向到 https,但“.secret/”目录除外,该目录应继续用作 http。

因此,例如:

  • http://example.com/a.html-->https://example.com/a.html
  • http://example.org/z/b.html-->https://example.org/z/b.html
  • http://example.com/.secret/x.html-->http://example.com/.secret/x.html

我的配置中有以下内容,但对于 http,它返回包含“_”的地址。

server {
    listen 80;
 
    server_name _;
 
    location /.secret {
        return http://$server_name$request_uri;
    }
 
    location / {
        return 301 https://$server_name$request_uri;
    }
}

我究竟做错了什么?

更新:

结合来自@mforsetti 和@Pothi_Kalimuthu 的评论,以下工作有效:

server {
    listen 80;
 
    server_name _;
 
    location /.secret { }
 
    location / {
        return 301 https://$host$request_uri;
    }
}
redirect nginx 301-redirect
  • 1 个回答
  • 1393 Views
Martin Hope
Perrschy
Asked: 2021-07-10 06:29:02 +0800 CST

nginx - 301 重定向外部网站上使用的错误 URL

  • 1

出于某种原因,一些外部网站有指向我的网站 subdomain.example.com 的链接,看起来像这样:<a href="https://subdomain.example.com/https://subdomain.example.com/index.php?id=54597">Link</a>

我无法更正这些链接,因为我无法控制这些链接。因此,我不想显示 404 错误,而是想通过 nginx 重定向https://subdomain.example.com/https://subdomain.example.com/index.php?id=54597到https://subdomain.example.com/index.php?id=54597,但是一旦包含冒号,我就无法获得匹配的位置。有没有办法让它工作?

就像是

location ~ "^https://subdomain.example.com/index.php$" {
  return 301 /index.php?$query_string;
}
redirect nginx 301-redirect
  • 1 个回答
  • 44 Views
Martin Hope
Zehke
Asked: 2021-05-27 00:30:19 +0800 CST

错误重定向到 www.www2.example.de 的原因是什么

  • 0

我为我们的主要网站设置了一个测试服务器www.example.com。
我将 apache-sites-config 设置为www2.example.com.
我删除了.htaccess/ 调整它以保存基本的 wordpress 条目。
我禁用了浏览器的自动完成功能。

当我进入时,www2.example.com我被重定向并永久移动到www.www2.example.com.

当我进入时,192.168.0.1我被重定向到www.www2.example.com.

有人可以告诉错误可能在哪里吗?

.htaccess:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

sites-config for the first vHost:

<VirtualHost *:80>
     Protocols h2 http/1.1
     ServerAdmin info@example.de
     DocumentRoot /var/www/html/
     ServerName www2.example.de
     ServerAlias www2.example.de

     <Directory /var/www/html>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

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


<VirtualHost *:443>
        ServerAdmin info@example.de
        Protocols h2 h2c http/1.1
        DocumentRoot /var/www/html/
        ServerName www2.example.de
        ServerAlias www2.example.de

        # added 01.04.2019 BEGINN
        <Directory /var/www/html>
                Options -Indexes +FollowSymLinks
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>
        # added 01.04.2019 END
        <Directory /var/www/html/>
          Options -Indexes +FollowSymlinks
          AllowOverride All
          Require all granted
         allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine off
</VirtualHost>
</IfModule>

sites-config for second vHost

<VirtualHost *:80>
     Protocols h2 http/1.1
     ServerAdmin info@example.de
     DocumentRoot /var/www/html1/example2/
     ServerName www2.example2.eu
     ServerAlias www2.example2.eu

     <Directory /var/www/html1/example2>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

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

The request- and response-header for www2.example.de

Connection:     Keep-Alive
Content-Length: 236
Content-Type:   text/html; charset=iso-8859-1
Date:           Wed, 26 May 2021 10:41:46 GMT
Expires:        Wed, 26 May 2021 10:42:46 GMT
Keep-Alive:     timeout=5, max=100
Location:       https://www.www2.example.de/
Server:         Apache


Accept:         text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:de,en-US;q=0.7,en;q=0.3
Cache-Control:  no-cache
Connection:     keep-alive
DNT:            1
Host:           www2.example.de
Pragma:         no-cache
Upgrade-Insecure-Requests:  1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0
web-server .htaccess wordpress 301-redirect
  • 2 个回答
  • 73 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve