diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4c8da88 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Nginx CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + lint-nginx: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nginx + run: sudo apt-get update && sudo apt-get install -y nginx + + - name: Create logs directory + run: mkdir -p infra/nginx/logs + + - name: Test Nginx configuration + run: sudo nginx -t -p infra/nginx/ -c nginx.conf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8506864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# .gitignore +infra/nginx/logs/*.log +infra/nginx/logs/*.pid \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3711333 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "frontend"] + path = frontend + url = git@github.com:Codzilla-HSE/frontend.git diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5582b76 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + { + "associatedIndex": 5 +} + + + + + + + + + + + + + + + + + + + + + + + + 1772824345782 + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index cf19fc2..2ccdd15 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ -# Application \ No newline at end of file +# nginx + +## Зависимости + +Для работы понадобится установленный `nginx`. +* **Ubuntu/Debian:** `sudo apt install nginx` +* **macOS:** `brew install nginx` + +> **Важно:** Убедитесь, что системный сервис nginx (если он запустился после установки) остановлен, чтобы он не занимал 80-й порт: +> `sudo lsof -i :80` (чтобы узнать занимает или нет) +> `sudo systemctl stop nginx` (Linux) или `brew services stop nginx` (macOS). + +## Как запустить локально + +1. Перейдите в папку с конфигурацией: + ```bash + cd infra/nginx +2. Запустите Nginx в привязанном к терминалу режиме (чтобы видеть ошибки и легко останавливать через Ctrl+C): + ```bash + sudo nginx -p . -c nginx.conf -g "daemon off;" + Сервер будет доступен по адресу http://localhost +3. Для проверки синтаксиса локально: + ```bash + sudo nginx -t -p . -c nginx.conf + ``` + Вы должны увидеть: + ```bash + nginx: the configuration file ./nginx.conf syntax is ok + nginx: configuration file ./nginx.conf test is successful + +4. Если вы запустили его в фоновом режиме (без daemon off;), остановить его можно командой из папки infra/nginx: + ```bash + sudo nginx -p . -c nginx.conf -s stop \ No newline at end of file diff --git a/frontend b/frontend new file mode 160000 index 0000000..8799bc3 --- /dev/null +++ b/frontend @@ -0,0 +1 @@ +Subproject commit 8799bc3910b7690326c899319a6af34ee2b9e8f2 diff --git a/infra/nginx/logs/.gitkeep b/infra/nginx/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/infra/nginx/mime.types b/infra/nginx/mime.types new file mode 100644 index 0000000..1c00d70 --- /dev/null +++ b/infra/nginx/mime.types @@ -0,0 +1,99 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/infra/nginx/nginx.conf b/infra/nginx/nginx.conf new file mode 100644 index 0000000..0b3cd60 --- /dev/null +++ b/infra/nginx/nginx.conf @@ -0,0 +1,67 @@ +worker_processes 1; +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml; + gzip_min_length 1000; + client_max_body_size 10M; + add_header X-Frame-Options "SAMEORIGIN"; + add_header X-Content-Type-Options "nosniff"; + sendfile on; + keepalive_timeout 65; + + upstream backend_servers { + server backend:8080; + } + + server { + listen 80; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /auth/ { + proxy_pass http://backend_servers; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /problems/ { + proxy_pass http://backend_servers; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /submissions/ { + proxy_pass http://backend_servers; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /ws/ { + proxy_pass http://backend_servers; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } + } +} \ No newline at end of file