1
votes

I got Nginx server with HTTP (80 port) and HTTPS (443). But it is behind router and port forwarding is like 17014 for HTTP and 17004 for HTTPS. Redirection from HTTP to HTTPS works well but I have problems with request for HTTPS. For example I should see my application when I'm going to address "https://domain:17004" but I can see it only when I'm going to "https://domain:port/panel_admin/login". How to write correct rewrite rule or something? Here is my actually configuration:

server {
    listen         80;
    listen         [::]:80;
    rewrite ^ https://strona:port_1$request_uri? permanent; 
}
server {
    listen 443 ssl;
    ssl_certificate /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.cert;
    ssl_certificate_key /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.key;

    location / {
       proxy_pass http://localhost:4000;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
    }

    location /static {
       alias /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/static/;
    }
}
1
You have configuration that listens port 443 to the outside and proxy to port 4000. Where is port 17004? What is port_1? - Anatoly

1 Answers

0
votes

I solved the problem. Correct configuration looks like

server {
listen         80;
listen         [::]:80;
rewrite ^ https://strona:port_https$request_uri? permanent;
}
server {
listen 443 ssl;
ssl_certificate /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.cert;
ssl_certificate_key /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.key;

location / {
   proxy_pass http://localhost:4000;
   proxy_set_header Host $host:port_http;
   proxy_set_header X-Real-IP $remote_addr;
}

location /static {
   alias /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/static/;
}
}

So no rewrite. :)