From 3d1e9f602f7285dcf176a1cf12f743f5a3201054 Mon Sep 17 00:00:00 2001 From: AyomideA-S Date: Sat, 24 Aug 2024 10:43:36 +0100 Subject: [PATCH] Application server --- .../2-app_server-nginx_config | 51 +++++------- .../3-app_server-nginx_config | 53 ++++++------ .../4-app_server-nginx_config | 61 ++++++-------- .../5-app_server-nginx_config | 76 +++++++---------- 0x1A-application_server/app_server_script | 83 +++++++++++++++++++ 0x1A-application_server/gunicorn.service | 20 +++++ 6 files changed, 206 insertions(+), 138 deletions(-) create mode 100644 0x1A-application_server/app_server_script create mode 100644 0x1A-application_server/gunicorn.service diff --git a/0x1A-application_server/2-app_server-nginx_config b/0x1A-application_server/2-app_server-nginx_config index 59f375a..fcab57a 100755 --- a/0x1A-application_server/2-app_server-nginx_config +++ b/0x1A-application_server/2-app_server-nginx_config @@ -1,38 +1,27 @@ -# server { -# listen 80; -# listen [::]:80; -# -# server_name 3.238.176.253; -# -# location / { -# proxy_set_header X-Served-By 9401-web-01; -# proxy_pass http://127.0.0.1:5000/airbnb-onepage/; -# } -# } - -# Configures Nginx to serve the route /airbnb-onepage/ from AirBnB_clone_v2. - server { - # Listen on port 80 - listen 80; - listen [::]:80; - - # Use IP of server as domain name - server_name 3.238.176.253; + listen 80; + listen [::]:80 default_server; + add_header X-Served-By $hostname; + root /etc/nginx/html; + index index.html index.htm; + location /redirect_me { + return 301 https://www.youtube.com/watch?v=QH2-TGUlwu4; + } + root /var/www/html; - # Customize HTTP response header - add_header X-Served-By 9401-web-01; + server_name _; - # Serve /airbnb-onepage/ route from AirBnB_clone_v2 - location = /airbnb-onepage/ { - proxy_pass http://127.0.0.1:5000/airbnb-onepage/; + location /airbnb-onepage { + proxy_pass http://0.0.0.0:5000/airbnb-onepage; } - # 404 error page - error_page 404 /404.html; - location /404 { - root /var/www/html; - internal; + location /hbnb_static { + alias /data/web_static/current/; } -} + location /{ + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } +} \ No newline at end of file diff --git a/0x1A-application_server/3-app_server-nginx_config b/0x1A-application_server/3-app_server-nginx_config index e1d445d..e832836 100755 --- a/0x1A-application_server/3-app_server-nginx_config +++ b/0x1A-application_server/3-app_server-nginx_config @@ -1,30 +1,25 @@ -# Configures Nginx to serve the /number_odd_or_even/ route on AirBnB_clone_v2. - server { - # Listen on port 80 - listen 80; - listen [::]:80; - - # Use server IP as domain name - server_name 3.238.176.253; - - # Customize HTTP response header - add_header X-Served-By 9401-web-01; - - # Serve /airbnb-onepage/ route on AirBnB_clone_v2 - location = /airbnb-onepage/ { - proxy_pass http://127.0.0.1:5000/airbnb-onepage/; - } - - # Serve /number_odd_or_even/ route on AirBnB_clone_v2 - location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { - proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; - } - - # 404 error page - error_page 404 /404.html; - location /404 { - root /var/www/html; - internal; - } -} + listen 80 default_server; +location /hbnb_static { alias /data/web_static/current/;} + listen [::]:80 default_server; + root /var/www/html; + index index.html index.htm index.nginx-debian.html + server_name_; + add_header X-Served-By $hostname; + location / { + try_files $uri $uri/ =404; + } + location /airbnb-onepage { + proxy_pass http://0.0.0.0:5000/airbnb-onepage; + } + location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { + proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; + } + if ($request_filename ~ redirect_me){ + rewrite ^ https://th3-gr00t.tk/ permanent; + } + error_page 404 /error_404.html; + location = /error_404.html { + internal; + } +} \ No newline at end of file diff --git a/0x1A-application_server/4-app_server-nginx_config b/0x1A-application_server/4-app_server-nginx_config index a70f28a..6800184 100755 --- a/0x1A-application_server/4-app_server-nginx_config +++ b/0x1A-application_server/4-app_server-nginx_config @@ -1,35 +1,28 @@ -# Configures Nginx to serve the AirBnB_clone_v3 API. - server { - # Listen on port 80 - listen 80; - listen [::]:80; - - # Use server IP as domain name - server_name 3.238.176.253; - - # Customize HTTP response header - add_header X-Served-By 9401-web-01; - - # Serve /airbnb-onepage/ route on AirBnB_clone_v3 - location = /airbnb-onepage/ { - proxy_pass http://127.0.0.1:5000/airbnb-onepage/; - } - - # Serve /number_odd_or_even/ route on AirBnB_clone_v3 - location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { - proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; - } - - # Serve API on AirBnB_clone_v3 - location /api { - proxy_pass http://127.0.0.1:5002/api; - } - - # 404 error page - error_page 404 /404.html; - location /404 { - root /var/www/html; - internal; - } -} + listen 80 default_server; +location /hbnb_static { alias /data/web_static/current/;} + listen [::]:80 default_server; + root /var/www/html; + index index.html index.htm index.nginx-debian.html + server_name_; + add_header X-Served-By $hostname; + location / { + try_files $uri $uri/ =404; + } + location /airbnb-onepage { + proxy_pass http://0.0.0.0:5000/airbnb-onepage; + } + location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { + proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; + } + location /api/ { + proxy_pass http://0.0.0.0:5002; + } + if ($request_filename ~ redirect_me){ + rewrite ^ https://th3-gr00t.tk/ permanent; + } + error_page 404 /error_404.html; + location = /error_404.html { + internal; + } +} \ No newline at end of file diff --git a/0x1A-application_server/5-app_server-nginx_config b/0x1A-application_server/5-app_server-nginx_config index 4340122..9b968fa 100755 --- a/0x1A-application_server/5-app_server-nginx_config +++ b/0x1A-application_server/5-app_server-nginx_config @@ -1,45 +1,33 @@ -# Configures Nginx to serve the complete AirBnB_clone_v4 application. - server { - # Listen on port 80. - listen 80; - listen [::]:80; - - # Use server IP as domain name - server_name 3.238.176.253; - - # Customize HTTP response header - add_header X-Served-By 9401-web-01; - - # Serve /airbnb-onepage/ route on AirBnB_clone_v2 - location = /airbnb-onepage/ { - proxy_pass http://127.0.0.1:5000/airbnb-onepage/; - } - - # Serve /number_odd_or_even/ route on AirBnB_clone_v2 - location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { - proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; - } - - # Serve AirBnB_clone_v3 API - location /api { - proxy_pass http://127.0.0.1:5002/api; - } - - # Configure /2-hbnb route of AirBnB_clone_v4 as root location - location / { - proxy_pass http://127.0.0.1:5003/2-hbnb; - } - - # Serve static content for AirBnB_clone_v4 - location /static { - proxy_pass http://127.0.0.1:5003; - } - - # 404 error page - error_page 404 /404.html; - location /404 { - root /var/www/html; - internal; - } -} + listen 80 default_server; +location /hbnb_static { alias /data/web_static/current/;} + listen [::]:80 default_server; + root /var/www/html; + index index.html index.htm index.nginx-debian.html + server_name_; + add_header X-Served-By $hostname; + location /static/ { + # rewrite ^(/static/[^?]*)\?.*$ $1 last; + alias /home/ubuntu/AirBnB_clone_v4/web_dynamic/static/; + try_files $uri $uri/ =404; + } + location / { + try_files $uri $uri/ =404; + } + location /airbnb-onepage { + proxy_pass http://0.0.0.0:5000/airbnb-onepage; + } + location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { + proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; + } + location /api/ { + proxy_pass http://0.0.0.0:5002; + } + if ($request_filename ~ redirect_me){ + rewrite ^ https://th3-gr00t.tk/ permanent; + } + error_page 404 /error_404.html; + location = /error_404.html { + internal; + } +} \ No newline at end of file diff --git a/0x1A-application_server/app_server_script b/0x1A-application_server/app_server_script new file mode 100644 index 0000000..08a2cf1 --- /dev/null +++ b/0x1A-application_server/app_server_script @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +echo "Updating Packages and Installing Requirements" + +# Update Package Manager +sudo apt-get update +sudo apt-get install -y nginx +# Install pip +sudo apt-get install -y python3-pip +# Install Flask, flask_cors, sqlalchemy Using PIP +pip install flask +pip install flask_cors +pip install sqlalchemy +# Install net-tools +sudo apt install -y net-tools +# Install GUNICORN +sudo apt-get install -y gunicorn +# Remove any current AIRBNB Repositoty +rm -rf AirBnB_clone_v* +# Clone My Repository +git clone https://github.com/AyomideA-S/AirBnB_clone_v2 +git clone https://github.com/AyomideA-S/AirBnB_clone_v3 +git clone https://github.com/AyomideA-S/AirBnB_clone_v4 +# Change Directory +cd AirBnB_clone_v2 +# Switch Branches +git checkout app-server + +# Define the path to the Nginx configuration file to be overwritten +NGINX_CONFIG="/etc/nginx/sites-enabled/default" + +# Overwrite the Nginx configuration file with the provided configuration +sudo tee "$NGINX_CONFIG" > /dev/null <