0

I have set up Nginx with example.com to point to

/home/public_html/

which is root folder of app. I also configured Nginx as proxy pass to Varnish and SSL termination. Everything working.

As I am not very good to this, now I want to create a subdomain cdn.example.com to use it as cname in Cloudflare.

I have 3 nginx configuration files:

default

upstream fastcgi_backend {
  server   unix:/var/run/php/php7.2-fpm.sock;
}

server {
    server_name example.com www.example.com;
include includes/redirects.conf;
listen 8082;
access_log /var/log/nginx/example-com-access.log;
    error_log /var/log/nginx/example-com-error.log;

    include /home/public_html/nginx.conf;}

proxy-pass

server {
    listen 80;
    server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}

ssl

server {
    listen 443 ssl http2;
    server_name www.example.com;
    ssl on;
    ssl_certificate /etc/nginx/ssl/2018/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/2018/example.key;
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    return 301 https://example.com$request_uri;
}




server {
    listen 443 ssl http2;
    server_name example.com;
    ssl on;
    ssl_certificate /etc/nginx/ssl/2018/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/2018/example.key;
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    keepalive_timeout 300s;
    location / {
        proxy_pass http://127.0.0.1:6081;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
        proxy_buffer_size          128k;
        proxy_buffers              4 256k;
        proxy_busy_buffers_size    256k;
    }
}

My cdn.example.com subdomain must point to same root folder with example.com.

So if I put in server_name

server_name example.com www.example.com cdn.example.com;

will it work?

Also do I need to put this in first 2 files only? Any help because I am newbie

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.