0

Just moved my website over from IIS to Linux (LEMP on Ubuntu Server 16.04)

Still learning Linux, and im not sure how to achiveve the following:

I have a website running - lets say www.qwerty.com with google analytics set up for it. Lets say this lives in /var/www/html/qwerty.com/public

I want to create a virtual directory under this site, to serve 2 seperate pages with an embededed video player and video in.

lets say:

www.qwerty.com/videos contains all the files to serve Video #1 and lives in /var/www/html/videos

www.qwerty.com/videos/video2 contains all the files to serve video #2 and lives in /var/www/html/videos/video2

I want to do this as both of these page url's have their own respective individual google analytics code so visitors are tracked uniquely to these pages and not all under qwerty.com.

Do i achieve this by using symlinks for the video1 and video 2 directories pointing to the main /var/www/html/qwerty.com/public directory?

Thanks for your help

SERVER BLOCK ADDED EDIT

fastcgi_cache_path /var/www/html/qwerty.com/cache levels=1:2 keys_zone=QWERTY:100m inactive=60m;

server {

server_name www.qwerty.com

    root /var/www/html/qwerty.com/public/;  

    index index.php index.html index.htm video.html;

location ~ /\. {
    deny all;
    }

location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
    }

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Xss-Protection "1; mode=block" always;

location = /robots.txt {
    log_not_found off;
    access_log off;
    }

location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
    {
        return 444;
    }

location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off;
    log_not_found off;
    expires max;
    }

location ~* \.(pl|cgi|py|sh|lua)\$ {
    return 444;
    }

    location /videos {
            root /var/www/html;
            }

    location /videos/videos2 {
            root /var/www/html;
            }

set $skip_cache 0;

if ($request_method = POST) {
    set $skip_cache 1;
}

if ($query_string != "") {
    set $skip_cache 1;
}

if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $skip_cache 1;
    }

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
}

if ($http_cookie ~* "PHPSESSID"){
    set $skip_cache 1;
}

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

location /phpmyadmin {
    auth_basic "Admin Login";
    auth_basic_user_file /etc/nginx/allow_phpmyadmin;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
    expires -1;
    }

location ~* \.(?:rss|ato)$ {
    expires 1h;
    add_header Cache-Control "public";
    }

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 1d;
    add_header Cache-Control "public";
    log_not_found off;
    access_log off;
    }

location ~* \.(?:css|js)$ {
    expires 7d;
    add_header Cache-Control "public";
    }

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache QWERTY;
    fastcgi_cache_valid 60m;
}

location ~ /purge(/.*) {
    fastcgi_cache_purge QWERTY "$scheme$request_method$host$1";
}

}

2 Answers2

0

Just add a location block within your existing server block. This might not be perfect but should give you a good idea.

location /videos/ {
  root /var/www/html/;
}

Add additional location blocks for any others you require.

You might end up needing slightly more complex path matching logic, say regular expressions or wildcards. There's a good tutorial here.

Tim
  • 30,383
  • 6
  • 47
  • 77
  • This won't work, since the URL `www.example.com/videos/video1/something.mpg` would resolve to `/var/www/html/videos/videos/video1` directory in nginx. Remember, nginx appends the `location` directory after `root`. – Tero Kilkanen Dec 05 '16 at 18:24
  • This goes into the qwerty.com server block yes? – nginxnovice Dec 05 '16 at 18:52
  • Yes, under your current location(s). If you want to see some example config files have a look at my Nginx/Wordpress tutorial: https://www.photographerstechsupport.com/tutorials/hosting-wordpress-on-aws-tutorial-pt1-introduction-configuration-downloads/#wpmu-nginx-configuration-files – Tim Dec 05 '16 at 19:00
  • ok, so when i now go to www.qwerty.com/videos i get a 403 Forbidden messgae. When i go to what i want the default file to be for video1 at www.qwerty.com/videos/video.html i get a 404 Not Found? I have added my server block to the main post (clensed version) – nginxnovice Dec 05 '16 at 19:32
  • A direct copy and paste might not work. You're going to have to understand the principal, check access and error logs, and generally give it some thought. – Tim Dec 05 '16 at 19:55
  • got it - defautl document needed to be index.html and not video.html. Both links work now. Thankyou for your assistance – nginxnovice Dec 06 '16 at 09:42
  • Great :) That's what "index index.php index.html index.htm video.html;" is meant to do. Please accept an answer so the question is marked as not requiring an answer. – Tim Dec 06 '16 at 18:00
0

The nginx way for doing is this:

location /videos {
    root /var/www/html;
}

Here we set up a different root directory for nginx for URIs beginning with /videos. Since nginx appends the videos automatically after the directory specified in root, we have /var/www/html only there.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58