diff --git a/configs/nginx/folder.conf b/configs/nginx/folder.conf new file mode 100644 index 0000000..550b70f --- /dev/null +++ b/configs/nginx/folder.conf @@ -0,0 +1,77 @@ +server { + listen 80; + server_name localhost; + + root /var/www/html; + index index.html; + + # Security headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header X-Content-Type-Options "nosniff" always; + + # Deny access to hidden files + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } + + # PHP routing - everything under /tkr goes through index.php + location /tkr { + alias /var/www/html/public; + index index.php; + + # index.php is the entry point + # It needs to be sent to php-fpm + # But if someone tries to directly access index.php, that file will throw a 404 + # so bots and scanners can't tell this is a php app + location = /tkr/index.php { + fastcgi_pass php:9000; + fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php; + include fastcgi_params; + + # Additional FastCGI params + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param QUERY_STRING $query_string; + } + + # Block attempts to access all other .php files directly + # (these are bots and scanners) + location ~ ^/tkr/.+\.php$ { + return 404; + } + + # forward other requests to the fallback block, + # which sends them to php-fpm for handling + try_files $uri $uri/ @tkr_fallback; + } + + # Fallback for /tkr routing - all non-file requests go to index.php + location @tkr_fallback { + fastcgi_pass php:9000; + fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php; + include fastcgi_params; + + # Additional FastCGI params + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param QUERY_STRING $query_string; + } + + # Cache static files + # Note that I don't actually serve most of this (just js and css to start) + # but including them all will let caching work later if I add images or something + location ~* ^/tkr/.+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } + + # Deny access to sensitive directories + location ~ ^/tkr/(storage|lib|vendor|config) { + deny all; + return 404; + } +} \ No newline at end of file diff --git a/examples/nginx/tkr-nginx.conf b/configs/nginx/root.conf similarity index 56% rename from examples/nginx/tkr-nginx.conf rename to configs/nginx/root.conf index 42266d0..6f7f869 100644 --- a/examples/nginx/tkr-nginx.conf +++ b/configs/nginx/root.conf @@ -1,9 +1,22 @@ server { - listen 80 default_server; + #listen 80 default_server; + listen 80; root /app/public; - index index.php index.html index.htm; + index index.php; + # Security headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header X-Content-Type-Options "nosniff" always; + + # Deny access to hidden files + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } + location ~ \.php$ { fastcgi_pass php:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f763954 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +services: + nginx: + image: nginx:alpine + container_name: nginx-server + ports: + - "80:80" + volumes: + - ./src:/var/www/html + - ./configs/nginx/folder.conf:/etc/nginx/conf.d/default.conf + depends_on: + - php + restart: unless-stopped + + php: + image: php:8.2-fpm-alpine + container_name: php-fpm + volumes: + - ./src:/var/www/html + command: > + sh -c " + chown -R www-data:www-data /var/www/html/storage && + chmod -R 775 /var/www/html/storage && + php-fpm + " + restart: unless-stopped + +volumes: + src: + driver: local \ No newline at end of file diff --git a/examples/nginx/docker-compose.yml b/examples/nginx/docker-compose.yml deleted file mode 100644 index 72631d4..0000000 --- a/examples/nginx/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - web: - image: nginx:latest - ports: - - "80:80" - volumes: - - ./tkr-nginx-folder.conf:/etc/nginx/conf.d/default.conf - - ./../../tkr:/tkr - php: - image: php:fpm - volumes: - - ./../../tkr:/tkr \ No newline at end of file diff --git a/examples/nginx/tkr-nginx-folder.conf b/examples/nginx/tkr-nginx-folder.conf deleted file mode 100644 index b38f449..0000000 --- a/examples/nginx/tkr-nginx-folder.conf +++ /dev/null @@ -1,29 +0,0 @@ -server { - listen 80 default_server; - root /usr/share/nginx/html; - - location ^~ /tkr { - index index.php; - alias /tkr/public; - - location ~ ^/tkr(/.+\.php)$ { - fastcgi_pass php:9000; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME /tkr/public/$1; - fastcgi_param SCRIPT_NAME $uri; - fastcgi_param REQUEST_METHOD $request_method; - fastcgi_param CONTENT_TYPE $content_type; - fastcgi_param CONTENT_LENGTH $content_length; - } - } - - # Deny anything else - location / { - try_files $uri $uri/ =404; - } - - # Deny access to hidden or stray files - location ~* \.(htaccess|env|ini|log|bak)$ { - deny all; - } -} \ No newline at end of file diff --git a/tkr/bootstrap.php b/src/bootstrap.php similarity index 100% rename from tkr/bootstrap.php rename to src/bootstrap.php diff --git a/tkr/classes/Config.php b/src/classes/Config.php similarity index 100% rename from tkr/classes/Config.php rename to src/classes/Config.php diff --git a/tkr/classes/User.php b/src/classes/User.php similarity index 100% rename from tkr/classes/User.php rename to src/classes/User.php diff --git a/tkr/lib/emoji.php b/src/lib/emoji.php similarity index 100% rename from tkr/lib/emoji.php rename to src/lib/emoji.php diff --git a/tkr/lib/mood.php b/src/lib/mood.php similarity index 100% rename from tkr/lib/mood.php rename to src/lib/mood.php diff --git a/tkr/lib/session.php b/src/lib/session.php similarity index 100% rename from tkr/lib/session.php rename to src/lib/session.php diff --git a/tkr/lib/ticks.php b/src/lib/ticks.php similarity index 100% rename from tkr/lib/ticks.php rename to src/lib/ticks.php diff --git a/tkr/lib/util.php b/src/lib/util.php similarity index 100% rename from tkr/lib/util.php rename to src/lib/util.php diff --git a/tkr/public/admin.php b/src/public/admin.php similarity index 100% rename from tkr/public/admin.php rename to src/public/admin.php diff --git a/tkr/public/atom/index.php b/src/public/atom/index.php similarity index 100% rename from tkr/public/atom/index.php rename to src/public/atom/index.php diff --git a/tkr/public/css/tkr.css b/src/public/css/tkr.css similarity index 100% rename from tkr/public/css/tkr.css rename to src/public/css/tkr.css diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..b35c36c --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,48 @@ +Home Page'; + echo '

Welcome to the home page!

'; +}); diff --git a/tkr/public/index.php b/src/public/index.php.bak similarity index 100% rename from tkr/public/index.php rename to src/public/index.php.bak diff --git a/tkr/public/login.php b/src/public/login.php similarity index 100% rename from tkr/public/login.php rename to src/public/login.php diff --git a/tkr/public/logout.php b/src/public/logout.php similarity index 100% rename from tkr/public/logout.php rename to src/public/logout.php diff --git a/tkr/public/rss/index.php b/src/public/rss/index.php similarity index 100% rename from tkr/public/rss/index.php rename to src/public/rss/index.php diff --git a/tkr/public/save_tick.php b/src/public/save_tick.php similarity index 100% rename from tkr/public/save_tick.php rename to src/public/save_tick.php diff --git a/tkr/public/set_mood.php b/src/public/set_mood.php similarity index 100% rename from tkr/public/set_mood.php rename to src/public/set_mood.php diff --git a/tkr/public/setup.php b/src/public/setup.php similarity index 100% rename from tkr/public/setup.php rename to src/public/setup.php diff --git a/tkr/public/tick.php b/src/public/tick.php similarity index 100% rename from tkr/public/tick.php rename to src/public/tick.php diff --git a/tkr/storage/.gitkeep b/src/storage/.gitkeep old mode 100644 new mode 100755 similarity index 100% rename from tkr/storage/.gitkeep rename to src/storage/.gitkeep