0

I'm pretty new to nginx and I'm trying to configure a redirect from http to https and, in the same file, set as location a proxy_pass to the desired URL.

My domain.com file is this:

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;
}

}

if I run nginx -t I got sintax OK, if I reload nginx it reload w/out issues but if I point to my.domain.com I see default nginx page (in http), no redirect to https, non proxy_pass; if I point to https://my.example.com I got connection refused, if I point to https://other.example.org:10302/some/folder/ I can connect w/out any issue.

My certificate.crt is made with:

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

is it ok or I need to made it in a different way?

Anyone could point me in the right direction? Thanks in advance, Alessandro

  • I've "solved" https issue, there was a not defined in default conf file, set it and it works, but I still not have redirect from http to https and no proxy_pass. – Alessandro75 Jan 04 '24 at 11:29
  • Welcome to Server Fault! In your questions please refrain from using random / made-up domain names and use either your own domain or one of the RFC 6761 reserved domain names such as example.com, example.org or similar . Please refer to this Q&A for our recommendations with regards to how and what (not) to obfuscate in your questions. - Also see https://serverfault.com/q/725262 with regards to the connection refused because your configuration snippet looks OK – HBruijn Jan 04 '24 at 11:31
  • Hi @HBruijn and thanks for your reply! I have edited my 3D and changed with example.TLD. Regarding connection refused, I have solved, but I still have problems both for redirect 301 from HTTP to HTTPS and proxy_pass, because it don't work; now if I point to my.example.com in HTTPS I still landing on default NGINX page, certificate is loaded correctly, but I do not landing on the https://other.example.org:10302/some/folder/ – Alessandro75 Jan 04 '24 at 12:06
  • Please enable error log and access log in your vhost and provide relevant logging. Also have you linked the vhost from sites-available to sites-enabled? – Turdie Jan 04 '24 at 13:17
  • Provide error and access logging – Turdie Jan 04 '24 at 13:18
  • Ok, my fault! I had enabled my my.example.com but after that I had modify it under site-available and, don't ask me why, I had lost it under site-enebled. I had redo symlink, reload nginx and it works! Thanks to all for the support, solved! – Alessandro75 Jan 04 '24 at 14:07
  • I will add it as answer please up vote it. Was a wild guess from he hahaha been there done that myself also – Turdie Jan 04 '24 at 15:00

1 Answers1

0

Make sure the link of the vhost between sites-available and sites-enabled is there.

Turdie
  • 2,564