NGINX 域名配置文件,如何重定向 301 和 proxy_pass

NGINX 域名配置文件,如何重定向 301 和 proxy_pass

我对 nginx 还很陌生,我正在尝试配置从 http 到 https 的重定向,并在同一个文件中将位置 a proxy_pass 设置为所需的 URL。

我的 domain.com 文件是这样的:

server {
    listen 80;

    server_name my.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;

    server_name my.example.com;
        ssl on;
        ssl_certificate /etc/nginx/certificate/example.com/certificate.crt;
        ssl_certificate_key /etc/nginx/certificate/example.com/privkey.key;

    location / {
        proxy_pass https://other.example.org:10302/some/folder/;
        proxy_buffering off;
        include proxy_params;
    }
}

如果我运行 nginx -t,我得到了语法 OK,如果我重新加载 nginx,它会重新加载而不会出现问题,但如果我指向 my.domain.com,我会看到默认的 nginx 页面(在 http 中),没有重定向到 https,没有 proxy_pass;如果我指向https://my.example.com我被拒绝连接,如果我指向https://other.example.org:10302/some/folder/我可以毫无问题地连接。

我的 certificate.crt 由以下材料制成:

openssl x509 -in certificate.csr -out certificate.crt

可以吗?或者我需要用不同的方式来做?

有人能给我指点迷津吗?提前谢谢 Alessandro

答案1

确保 sites-available 和 sites-enabled 之间的 vhost 链接存在。

相关内容