nginx 不提供“/”路径

nginx 不提供“/”路径

我有一个已注册并正在运行的域名 example.com。

我现在正尝试将所有请求重定向example.comwww.example.com特定端口。

sites-enabled 中的配置default如下所示:

server{
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

     location / {
         return 301 https://example.com:8081/;
     }
}

上述配置不起作用(example.com在浏览器中访问时,出现无限加载)

当使用此配置时,example.com/test就可以工作。

server{
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

     location /test {
         return 301 https://example.com:8081/;
     }
}

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    include /etc/nginx/sites-enabled/*;
}

相关内容