Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Advertise on
Nginx ssl redirect
New on LowEndTalk? Please Register and read our Community Rules.

Nginx ssl redirect

rokokrokok Member
edited October 2014 in Help

hello guys newbie need some help here :D

i got 2 domain both with valid ssl cert, i want to redirect AAA domain to BBB domain with AAA cert to keep transfer green

the BBB config all good, but AAA have problem

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/

AAA config

server {
listen 80;
listen 443 ssl;
    ssl_certificate /etc/nginx/SSL/server.crt;
    ssl_certificate_key /etc/nginx/SSL/server.key;
    root /var/www/;
#rewrite ^(.*)$1 permanent;
return 301$request_uri;

all AAA non ssl OK redirect to (SSL)

AAA/* to BBB/* ssl

but the AAA SSL not redirect to BBB (SSL)
nginx 1.7.6

Thanked by 1linuxthefish

CEO of PT. Rokok Kopi Internet Tidur Tbk.


  • Not sure why you need the rewrite statement. 301 status already denotes permanent redirect.

    return 301$request_uri;

    should be adequate. Maybe that was interfering with the redirect?

    Thanked by 1rokok
  • ya can opt-out that line, but still only non ssl working, ssl blank page not redirect

    the AAA root directory is just dummy, can be removed to

    is there any possible way to do it smoothly :D there is alternative redirect but scarifying the ssl which is really not ok :(

    CEO of PT. Rokok Kopi Internet Tidur Tbk.

  • This is what I'm using:

    if ($ssl_protocol = "") {
            rewrite ^ https://$server_name$request_uri? permanent;
    Thanked by 1rokok

    LowEndHelpDesk | Find help to simple questions :-)

  • @catalystium said:

    that might be working on current domain only, not to redirect to BBB ssl

    CEO of PT. Rokok Kopi Internet Tidur Tbk.

  • Try

    rewrite ^$request_uri? permanent;

    Thanked by 1rokok
  • ^ not gonna work

    btw any BBB config modification are welcome

    im gooling like 6 hour for any possible solution still not found answer, becaused im dummy -_-

    CEO of PT. Rokok Kopi Internet Tidur Tbk.

  • Have you look at the access/error log?

  • BayuBayu Member
    edited October 2014

    Mas @rokok, bisa dicoba konfigurasi ini:

    Site AAA:

    location / {
    root    /menuju/ke/direktor/webnya;
    index   index.html index.php;  
    rewrite ^ https://ke.domain.tujuan$request_uri? permanent;    

    Saya pakai konfigurasi ini untuk redirect dari situs AAA yang non-ssl ke situs BBB yg SSL

    Thanked by 1rokok


  • vonlulzwegvonlulzweg Member without signature

    english please

  • vonlulzwegvonlulzweg Member without signature
    edited October 2014

    You need atleast 3 virtual host config (server block)

    1 - AAA non SSL => BBB

    2 - AAA SSL => BBB

    3- BBB

    here example

    server { server_name AAA; listen 80; return 301 https://BBB$request_uri; access_log off; }
    server { server_name AAA; listen 443;  return 301 https://BBB$request_uri; access_log off; }
    server { server_name BBB; listen 443;
    ## your code here
    Thanked by 1rokok
  • You don't need three virtual hosts; Nginx can handle multiple ports with optional SSL in a single server statement.

    To be honest, something is amiss. The originally posted config with the return directive (not rewrite) should work just fine. I've used similar configs myself without issue. @rokok needs to check Nginx's logs to see what's happening.

    @rokok, are you sure the config files are being included? My default nginx.conf file only includes sites-enabled/*.conf and based on the symlinks you posted your conf files do not end with that extension.

    Thanked by 1rokok
  • rokokrokok Member
    edited October 2014

    Hi, all sorry fall aspleep :D

    @Bayu the root directory are empty can be ignored, as said before its working on all non ssl, only https not working, need to get it works without interception leaving AAA and identity changed to BBB.

    @vonlulzweg i got your idea, its working just for non ssl, the https on AAA shows blank page :/

    @JustAMacUser there is no issue with symlinks all in correct order. a went to a b went to b default goes to default.

    this running on 1 vps, sni ssl just the BBB config im using
    listen 443 default spdy ssl;
    AAA config just use regular 433;
    also dont think this was problerm

    CEO of PT. Rokok Kopi Internet Tidur Tbk.

  • Ahaaa got it working !

    thanks all guys!

    here's my solution:


    CEO of PT. Rokok Kopi Internet Tidur Tbk.

Sign In or Register to comment.