Mixed application ssl nginx

June 5, 2018 84 views
Nginx Ubuntu 16.04
farkinid
By:
farkinid

I have an Apache Tomcat serving an application which is behind an Nginx with SSL encryption setup on my droplet. The domain is tomcat.mydomain.com. This has been setup and works fine. Nginx redirects to the tomcat server via tomcatproxy.conf found in /etc/nginx/conf.d/

server {
    server_name tomcat.mydomain.com;

    location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:8080/;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/pms.dataportsystems.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/pms.dataportsystems.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = tomcat.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name tomcat.mydomain.com;
    return 404; # managed by Certbot
}

Now I am attempting to install a non-tomcat php application found in /var/www/application/html. I've created a new subdomain called phpapplic.mydomain.com. I've added a new server block into the tomcatproxy.conf but it resolved to a bad gateway. The block I added is

server {
    server {
     listen 80 default_server;
     listen [::]:80 default_server;

     server_name phpapplic.mydomain.com;

     root /var/www/applicationName/html/public;
     index index.php index.html index.htm;

     location / {
         try_files $uri $uri/ /index.php$is_args$args;
     }

     location ~ \.php$ {
         fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
         include snippets/fastcgi-php.conf;
     }
}

At this point, I've tried multiple variations including attempting to use SSL on the phpapplic.mydomain.com but lets encrypt does not recognise that I have control over the domain because it resolved to a 404 bad gateway.

I'm out of ideas. Can anybody shed some light on this? Thank you so much.

Be the first one to answer this question.