Skip to content

Instantly share code, notes, and snippets.

@inecmc
Created March 2, 2018 06:54
Show Gist options
  • Save inecmc/31cbadcdd82545367a40546f2e891325 to your computer and use it in GitHub Desktop.
Save inecmc/31cbadcdd82545367a40546f2e891325 to your computer and use it in GitHub Desktop.
Nginx config for Vue.js history mode + Prerender.io
# Force to use https
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://$server_name$request_uri;
}

# Default server configuration
#
server {

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    #SSL
    ssl on;
    ssl_certificate /etc/nginx/ssl/example.com.cer;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    ssl_client_certificate /etc/nginx/ssl/rootca.cer;

    root /var/www/html/example.com;
    index index.html;
    server_name example.com;

    # log
    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;

    location / {
        try_files $uri @prerender;
    }

    location @prerender {
        proxy_set_header X-Prerender-Token <YOUR_PRERENDER_TOKEN>;
        set $prerender 0;
        if ($http_user_agent ~* "Googlebot|Mediapartners-Google|AdsBot-Google|bingbot|yahooseeker|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
            set $prerender 1;
        }
        if ($args ~ "_escaped_fragment_") {
            set $prerender 1;
        }
        if ($http_user_agent ~ "Prerender") {
            set $prerender 0;
        }
        if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
            set $prerender 0;
        }
        #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
        resolver 8.8.8.8;
        if ($prerender = 1) {
            #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
            set $prerender "service.prerender.io";
            rewrite .* /https://$host$request_uri? break;
            proxy_pass http://$prerender;
        }
        if ($prerender = 0) {
            rewrite .* /index.html last;
        }
    }
    
    # headers for html, other assets are hosted on cdn
    location ~ (index.html)$ {
        add_header Cache-Control "no-cache, max-age=0";
        add_header X-Frame-Options deny;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header Content-Security-Policy <YOUR_CSP>
    }

    location ~ /\.ht {
        deny all;
    }
}
@amirehosein
Copy link

Hello there. after installing and config the mosquitto plugin i have current error while i want to run the mosquitto server:
1575116340: |-- *** auth-plug: startup
1575116340: |-- ** Configured order: mysql

1575116340: |-- }}}} MYSQL
1575116340: |-- SSL is disabled
1575116340: |-- Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
any idea?
my mysql socket is in /home/mysql/mysql.sock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment