Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support]: Apache2 reverse proxy not entirely working #4496

Closed
blacknell opened this issue Nov 24, 2022 · 5 comments
Closed

[Support]: Apache2 reverse proxy not entirely working #4496

blacknell opened this issue Nov 24, 2022 · 5 comments

Comments

@blacknell
Copy link
Contributor

Describe the problem you are having

I've got my reverse proxy working but some of the embedded content is not displaying

Version

0.11.1-2EADA21

Frigate config file

ui:
  use_experimental: true

database:
  path: /media/frigate/frigate.db

# logger:
#   default: info
#   logs:
#     frigate.event: debug

cameras:
  front_door:
    zones:
      street:
        coordinates: 572,0,557,120,410,93,414,0
        objects:
          - car
          - person
      driveway:
        coordinates: 919,128,849,373,757,540,573,540,275,360,296,339,254,84,403,56,422,101,541,120,599,73
        objects:
          - person
          - car
        filters:
          car:
            min_area: 50000
      porch:
        coordinates: 305,540,547,540,259,359,287,339,245,0,0,0,0,540
        objects:
          - person
    motion:
      mask:
        - 935,45,935,21,855,21,854,45
    ffmpeg:
      inputs:
        - path: rtsp://stream:[email protected]/cam/realmonitor?channel=1&subtype=0
          roles:
            - record
        - path: rtsp://stream:[email protected]/cam/realmonitor?channel=1&subtype=1
          roles:
            - detect
detect:
  width: 960
  height: 540
  fps: 15

ffmpeg:
  hwaccel_args:
    - -c:v
    - h264_v4l2m2m

rtmp:
  enabled: false

birdseye:
  enabled: false

live:
  height: 576
  quality: 1

mqtt:
  host: 192.168.100.23
  topic_prefix: frigate
  client_id: frigate
  user: mqtt
  password: REDACTED

detectors:
#  cpu1:
#    type: cpu
#    num_threads: 4
  coral:
    type: edgetpu
    device: usb

objects:
  track:
    - person
    - car

record:
  enabled: true
  events:
    pre_capture: 2
    post_capture: 2
    retain:
      default: 14

snapshots:
  enabled: True
  bounding_box: True
  retain:
    default: 14
    objects:
      person: 28

Relevant log output

frigate  | Traceback (most recent call last):
frigate  |   File "/usr/lib/python3.9/wsgiref/handlers.py", line 137, in run
frigate  |     self.result = application(self.environ, self.start_response)
frigate  |   File "/usr/local/lib/python3.9/dist-packages/ws4py/server/wsgiutils.py", line 101, in __call__
frigate  |     raise HandshakeError('Header %s is not defined' % key)
frigate  | ws4py.exc.HandshakeError: Header HTTP_UPGRADE is not defined

FFprobe output from your camera

ffprobe version 4.3.5-0+deb11u1+rpt2 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr --extra-version=0+deb11u1+rpt2 --toolchain=hardened --incdir=/usr/include/aarch64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-mmal --enable-neon --enable-v4l2-request --enable-libudev --enable-epoxy --enable-sand --libdir=/usr/lib/aarch64-linux-gnu --arch=arm64 --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-vout-drm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[rtsp @ 0x55c5b3e870] method DESCRIBE failed: 404 Not Found
rtsp://stream:[email protected]/cam/realmonitor?channel=1: Server returned 404 Not Found

Frigate stats

{"detection_fps":0.0,"detectors":{"coral":{"detection_start":0.0,"inference_speed":14.42,"pid":216}},"front_door":{"camera_fps":15.0,"capture_pid":223,"detection_fps":0.0,"pid":222,"process_fps":15.0,"skipped_fps":0.0},"service":{"latest_version":"0.11.1","storage":{"/dev/shm":{"free":132.1,"mount_type":"tmpfs","total":134.2,"used":2.2},"/media/frigate/clips":{"free":81800.0,"mount_type":"ext4","total":472320.0,"used":371297.7},"/media/frigate/recordings":{"free":81800.0,"mount_type":"ext4","total":472320.0,"used":371297.7},"/tmp/cache":{"free":989.8,"mount_type":"tmpfs","total":1000.0,"used":10.2}},"temperatures":{},"uptime":272,"version":"0.11.1-2eada21"}}

Operating system

Other

Install method

Docker Compose

Coral version

USB

Network connection

Wired

Camera make and model

Dahua

Any other information that may be helpful

When I access the frigate UI via the reverse proxy , I get the usual page with a still shot of the camera etc.

  • Clicking on the camera snapshot loads another page with a black camera image (on frigatepi.local:5000 this shows the live stream just fine)
    image

  • Clicking on debug link does show the live stream, motion boxes etc. but...

    • The Live options also fails with black screen
    • Clicking on history also works and you can jump to events on the timeline
  • Events play back fine

@blacknell
Copy link
Contributor Author

I've made no changes on the frigate side (it runs on a dedicated Raspberry Pi)

Here is my Apache2 reverse proxy config (running on a separate gateway)

I added the ws lines because I saw these in another issue but I don't really understand them. Adding them didn't fix anything. I noted they probably relate to the error message above

    <VirtualHost *:443>
        ServerName cctv.mydomain.co.uk

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined

        ProxyPreserveHost On
        ProxyPass "/"  "http://frigatepi.local:5000/"
        ProxyPassReverse "/"  "http://frigatepi.local:5000/"
        
        ProxyPass /ws ws://frigatepi.local:5000/ws
        ProxyPassReverse /ws ws://frigatepi.local:5000/ws

        ProxyPass /live/ ws://frigatepi.local:5000/live/
        ProxyPassReverse /live/ ws://frigatepi.local:5000/live/

        Include /etc/letsencrypt/options-ssl-apache.conf
        ServerAlias cctv.blacknell.co.uk
        SSLCertificateFile /etc/letsencrypt/live/cctv.mydomain.co.uk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/cctv.mydomain.co.uk/privkey.pem

</VirtualHost>

@blacknell
Copy link
Contributor Author

I've partially fixed the problem by adding this to the apache2 config.

        RewriteEngine on
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*)  ws://frigatepi.local:5000/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /(.*)  http://frigatepi.local:5000/$1 [P,L]

But when viewing the history timeline each media snapshot (which itself displays) fails to play back the recorded video (nothing in the logs) but constantly showing the rotating wait hourglass
Screenshot 2022-11-24 at 11 00 54

@NickM-27
Copy link
Collaborator

It's confusing two different things are being talked about.

  1. Before you made that change were the recordings working?
  2. After this change does the live view work?
  3. Watching recordings is unrelated to the live view so browser or frigate logs for when trying to do this may be helpful.
  4. Also, highly recommend testing with the experimental UI disabled so we know that isn't a factor in this.

@blacknell
Copy link
Contributor Author

blacknell commented Nov 24, 2022

  1. Yes, playback of the recordings worked. But the live view did not
  2. Yes, the live view works but playback of recordings does not. Having said that restarted apache2 again and the playback now works. Most frustrating.
  3. n/a given 2
  4. n/a given 2

It does seem that perhaps I solved the problem and server bounce fixed it (I definitely had done that before, I promise) that this issue can be closed? Do you agree the ProxyPass/ProxyPassReverse ws entries are required?

I would like to contribute to the repo and add documentation of some recommendations for how to configure an apache2 reverse proxy - I have to think it's a common requirement. I'll raise a PR if you agree this is useful to the community.

@NickM-27
Copy link
Collaborator

Yes I'm sure it would be helpful, and I do believe it is necessary as it needs http upgrade since the live view is done over websocket

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

No branches or pull requests

2 participants