Running Behind Nginx

Calin Crisan edited this page May 28, 2017 · 2 revisions

Why Nginx?

Nginx is configurable, fast and easy to install. Running behind the Nginx webserver (using Nginx as a reverse proxy) can be useful when:

  • you want to use HTTPS with motionEye
  • you want to serve multiple websites (including motionEye) on the same webserver (accessible at the same IP address)
  • you want to take advantage of various Nginx modules (such as rate limiting or HTTP authentication)

Sample Virtual Host

Here's the content of a sample virtual host file that normally goes to /etc/nginx/sites-avaiable/

server {
    listen 80;
    location /cams/ {
        proxy_read_timeout 120s;
        access_log off;

Your motionEye UI will be available at It's important to note the trailing slashes at location /cams/ and at They make sure paths are correctly passed around when forwarding the HTTP requests to motionEye.

MJPEG And Nginx

motionEye doesn't normally rely on MJPEG streaming to present the live video to the user; it rather uses separate HTTP requests to repeatedly fetch the most recent JPEG for each camera frame.

However, if you explicitly add a Simple MJPEG Camera to your motionEye, it will require direct access to the given MJPEG stream that's usually accessible in your local network. There are two ways to make it accessible to the outside world:

  1. Configure port forwarding on your router so that the MJPEG port (often 8080) is forwarded to the IP address of your local MJPEG streaming camera; then make sure to (re)add your Simple MJPEG Camera with your public IP address instead of the local, private one.

  2. Add a new location directive to your Nginx configuration:

    location /mjpeg {
        proxy_pass http://your_netcam:8080/;
        proxy_read_timeout 86400;

    Then make sure to (re)add your Simple MJPEG Camera with your public IP address followed by the /mjpeg path.