Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 6d96cf9

Browse files
committed
Nginx hardering and refactor
1 parent b8f0534 commit 6d96cf9

File tree

10 files changed

+118
-70
lines changed

10 files changed

+118
-70
lines changed

src/modules/fluidd/filesystem/root/etc/nginx/conf.d/common_vars.conf

-4
This file was deleted.

src/modules/fluidd/filesystem/root/etc/nginx/conf.d/upstreams.conf

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
user www-data;
2+
worker_processes auto;
3+
4+
pid /run/nginx.pid;
5+
include /etc/nginx/modules-enabled/*.conf;
6+
7+
events {
8+
worker_connections 768;
9+
# multi_accept on;
10+
}
11+
12+
http {
13+
include /etc/nginx/mime.types;
14+
default_type application/octet-stream;
15+
16+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
17+
'$status $body_bytes_sent "$http_referer" '
18+
'"$http_user_agent" "$http_x_forwarded_for"';
19+
20+
access_log /var/log/nginx/access.log main;
21+
error_log /var/log/nginx/error.log warn;
22+
23+
sendfile on;
24+
tcp_nopush on;
25+
tcp_nodelay on;
26+
server_tokens off;
27+
keepalive_timeout 65;
28+
29+
gzip on;
30+
gzip_vary on;
31+
gzip_min_length 800;
32+
gzip_proxied expired no-cache no-store private auth;
33+
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
34+
35+
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
36+
'"$request" $status $body_bytes_sent '
37+
'"$http_referer" "$http_user_agent"';
38+
39+
access_log off;
40+
41+
include /etc/nginx/proxy.conf;
42+
include /etc/nginx/conf.d/*.conf;
43+
include /etc/nginx/sites-enabled/*;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
proxy_http_version 1.1;
2+
proxy_set_header Host $http_host;
3+
proxy_set_header Upgrade $http_upgrade;
4+
proxy_set_header Connection $proxy_connection;
5+
proxy_set_header X-Real-IP $remote_addr;
6+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
7+
proxy_set_header X-Forwarded-Port 443;
8+
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
2+
# scheme used to connect to this server
3+
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
4+
default $http_x_forwarded_proto;
5+
'' $scheme;
6+
}
7+
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
8+
# Connection header that may have been passed to this server
9+
map $http_upgrade $proxy_connection {
10+
default upgrade;
11+
'' close;
12+
}
13+
14+
## Enable default site
15+
#server {
16+
# server_name _; # This is just an invalid value which will never trigger on a real hostname.
17+
# listen 80;
18+
# access_log /var/log/nginx/access.log vhost;
19+
# return 503;
20+
#}
21+
#server {
22+
# server_name _; # This is just an invalid value which will never trigger on a real hostname.
23+
# listen 443 ssl http2;
24+
# access_log /var/log/nginx/access.log vhost;
25+
# return 503;
26+
# ssl_certificate /etc/nginx/certs/default.crt;
27+
# ssl_certificate_key /etc/nginx/certs/default.key;
28+
#}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
server {
2-
listen 80 default_server;
1+
upstream apiserver {
2+
ip_hash;
3+
server 127.0.0.1:7125;
4+
}
35

4-
access_log /var/log/nginx/fluidd-access.log;
5-
error_log /var/log/nginx/fluidd-error.log;
6+
upstream mjpgstreamer1 {
7+
ip_hash;
8+
server 127.0.0.1:8080;
9+
}
610

7-
# disable this section on smaller hardware like a pi zero
8-
gzip on;
9-
gzip_vary on;
10-
gzip_proxied any;
11-
gzip_proxied expired no-cache no-store private auth;
12-
gzip_comp_level 4;
13-
gzip_buffers 16 8k;
14-
gzip_http_version 1.1;
15-
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
11+
server {
12+
server_name _;
13+
listen 80 ;
14+
access_log /var/log/nginx/access.log vhost;
15+
## Enable https
16+
# return 301 https://$host$request_uri;
17+
#}
18+
#
19+
#server {
20+
# server_name elliot.grigri;
21+
# listen 443 ssl http2 ;
22+
# access_log /var/log/nginx/access.log vhost;
23+
# ssl_protocols TLSv1.1 TLSv1.2;
24+
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
25+
# ssl_prefer_server_ciphers on;
26+
# ssl_session_timeout 5m;
27+
# ssl_session_cache shared:SSL:50m;
28+
# ssl_certificate /etc/nginx/certs/fluidd.crt;
29+
# ssl_certificate_key /etc/nginx/certs/fluidd.key;
30+
# add_header Strict-Transport-Security "max-age=31536000";
31+
# add_header X-Frame-Options "SAMEORIGIN";
1632

1733
# web_path from fluidd static files
1834
root /home/pi/fluidd;
1935

2036
index index.html;
21-
server_name _;
2237

2338
# disable max upload size checks
2439
client_max_body_size 0;
@@ -36,36 +51,15 @@ server {
3651

3752
location /websocket {
3853
proxy_pass http://apiserver/websocket;
39-
proxy_http_version 1.1;
40-
proxy_set_header Upgrade $http_upgrade;
41-
proxy_set_header Connection $connection_upgrade;
42-
proxy_set_header Host $http_host;
43-
proxy_set_header X-Real-IP $remote_addr;
44-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4554
proxy_read_timeout 86400;
4655
}
4756

4857
location ~ ^/(printer|api|access|machine|server)/ {
4958
proxy_pass http://apiserver$request_uri;
50-
proxy_set_header Host $http_host;
51-
proxy_set_header X-Real-IP $remote_addr;
52-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
53-
proxy_set_header X-Scheme $scheme;
5459
}
55-
60+
5661
location /webcam/ {
5762
proxy_pass http://mjpgstreamer1/;
5863
}
59-
60-
location /webcam2/ {
61-
proxy_pass http://mjpgstreamer2/;
62-
}
63-
64-
location /webcam3/ {
65-
proxy_pass http://mjpgstreamer3/;
66-
}
67-
68-
location /webcam4/ {
69-
proxy_pass http://mjpgstreamer4/;
70-
}
7164
}
65+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d /var/log/nginx 0755 www-data www-data - -

src/modules/fluidd/start_chroot_script

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ echo "Installing Fluidd"
2222
apt update
2323
apt install nginx -y
2424
rm /etc/nginx/sites-enabled/default
25-
ln -s /etc/nginx/sites-available/fluidd /etc/nginx/sites-enabled/
25+
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
26+
ln -s /etc/nginx/sites-available/fluidd /etc/nginx/sites-enabled/fluidd
2627
cd /home/pi/
2728
[ ! -d /home/pi/gcode_files ] && su -c "mkdir /home/pi/gcode_files" - pi
2829
su -c "mkdir /home/pi/fluidd" - pi
@@ -37,4 +38,4 @@ ln -s /var/log/nginx/fluidd-error.log /home/pi/klipper_logs/
3738
# Run installation steps defined above
3839

3940
# Unpack root at the end, so files are modified before
40-
unpack /filesystem/root /
41+
unpack /filesystem/root /

src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# Current working directory is the mjpg-streamer base directory.
7070
#
7171
#camera_http_webroot="./www-fluidd"
72-
#camera_http_options="-n"
72+
camera_http_options="-n -l 127.0.0.1"
7373

7474
### EXPERIMENTAL
7575
# Support for different streamer types.

src/modules/moonraker/filesystem/home/pi/klipper_config/moonraker.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[server]
2-
host: 0.0.0.0
2+
host: 127.0.0.1
33
port: 7125
44
enable_debug_logging: False
55
config_path: ~/klipper_config
@@ -37,4 +37,4 @@ enable_auto_refresh: True
3737
[update_manager client fluidd]
3838
type: web
3939
repo: cadriel/fluidd
40-
path: ~/fluidd
40+
path: ~/fluidd

0 commit comments

Comments
 (0)