Skip to content

Commit ecff21e

Browse files
committed
Added Server setup
added folder server_setup containing cricial files for ubuntu sertver setup | nginx -> defult , *.mallickboy.com | gunicorn -> pysearch.service | Updated README.md with proper guidance and updated requirements.txt now using torch cpu version only so that it can be used in 2 GB RAM server
1 parent 8edf821 commit ecff21e

File tree

7 files changed

+200
-14
lines changed

7 files changed

+200
-14
lines changed

README.md

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,103 @@
11
<h1 align="center">
2-
Python Search Engine 2.0
2+
Python Search Engine 2.0 Server setup
33
</h1>
44

55
### Create virtual environment
66

7-
``` python -m venv search_engine ```
7+
``` mkdir pysearch ```
8+
9+
``` cd pysearch ```
10+
11+
``` sudo apt install python3.9 python3.9-venv python3.9-distutils ```
12+
13+
``` python3.9 -m venv pysearch ```
814

915
### Activate virtual environment (from parent folder)
1016

11-
```Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass```
17+
```Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass``` &
18+
19+
``` .\search_engine\Scripts\activate ``` or
20+
21+
``` source pysearch/bin/activate ```
1222

13-
``` .\search_engine\Scripts\activate ```
23+
### Install PyTorch ( lightweight CPU version only )
24+
25+
``` pip install torch --index-url https://download.pytorch.org/whl/cpu ```
1426

1527
### Install required libraries
1628

17-
``` pip install version_requirements.txt ```
29+
``` pip install -r requirements.txt ```
30+
31+
### Open firewall & update inbound port 8000 in Azure
32+
33+
``` sudo ufw enable ```
34+
35+
``` sudo ufw allow 8000 ```
36+
37+
``` sudo ufw status ```
38+
39+
### Run and Test
40+
41+
``` python app.py ```
42+
43+
Visit http://{your_server_ip}:8000
44+
45+
46+
<h2 align="center">
47+
Adding SSL, NGINX and deployment using GUNICORNN
48+
</h1>
49+
50+
### Deploy the site using gunicorn
51+
52+
``` gunicorn -w 4 -b 0.0.0.0:8000 app:app ```
53+
54+
``` sudo nano /etc/systemd/system/pysearch.service ``` paste code of server_setup/pysearch.service
55+
56+
``` sudo systemctl daemon-reload ```
57+
58+
``` sudo systemctl restart pysearch ```
59+
60+
``` sudo systemctl enable pysearch ```
61+
62+
``` sudo systemctl status pysearch ```
63+
64+
### Setup Domain/ Sub-Domain
65+
66+
Add New record in Advanced DNS in domain provider
67+
68+
``` Type = "A Record" Host= "pysearch" Value = "server public ip" TTL = "Automatic" ``` ( Sub-Domain )
69+
70+
``` Type = "A Record" Host= "@" Value = "server public ip" TTL = "Automatic" ``` ( Domain )
71+
72+
### Installing SSL certificate
73+
74+
``` sudo apt install certbot python3-certbot-nginx ```
75+
76+
``` sudo certbot --nginx -d pysearch.mallickboy.com ```
77+
78+
``` sudo certbot certificates ```
79+
80+
``` sudo systemctl status certbot.timer ``` check auto renewal
81+
82+
### Set-Up NGINX
83+
84+
``` sudo nano /etc/nginx/sites-available/pysearch.mallickboy.com ``` (copy contents of server_setup/pysearch.mallickboy.com)
85+
86+
``` sudo nano /etc/nginx/sites-available/default ``` (copy contents of server_setup/default)
87+
88+
``` sudo ln -s /etc/nginx/sites-available/pysearch.mallickboy.com /etc/nginx/sites-enabled/ ```
89+
90+
``` sudo nginx -t ```
91+
92+
``` sudo systemctl reload nginx ```
93+
94+
``` sudo systemctl restart nginx ```
95+
96+
### Visit
1897

19-
### Select kernel for Jupiter Notebook ( ipynb )
98+
[ https://pysearch.mallickboy.com ](https://pysearch.mallickboy.com)
2099

21-
From top right corner select ``` (parent_folder)/Scripts/python.exe ``` as kernel and run
22100

23-
For python file use ``` python file_name ``` to execute
24101

25102
<h1 align="center">
26103
Output View

requirements.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Flask==3.0.3
2-
flask-cors==5.0.0
3-
python-dotenv==1.0.1
4-
pinecone-client==5.0.1
5-
sentence-transformers==3.3.1
6-
gunicorn==20.1.0
1+
--extra-index-url https://download.pytorch.org/whl/cpu
2+
torch>=2.0.0
3+
Flask>=3.1.0
4+
flask-cors>=5.0.0
5+
python-dotenv>=1.0.0
6+
pinecone-client>=5.0.1
7+
sentence-transformers>=3.3.1
8+
gunicorn>=23.0.0

server_setup/default

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# NGINX default file settings
2+
server {
3+
listen 80 default_server;
4+
listen [::]:80 default_server;
5+
6+
root /var/www/html;
7+
8+
# Add index.php to the list if you are using PHP
9+
index index.html index.htm index.nginx-debian.html;
10+
11+
server_name _;
12+
13+
location / {
14+
# First attempt to serve request as file, then
15+
# as directory, then fall back to displaying a 404.
16+
try_files $uri $uri/ =404;
17+
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# sudo nano /etc/nginx/sites-available/pysearch.mallickboy.com
2+
server { # http only
3+
listen 80;
4+
server_name pysearch.mallickboy.com;
5+
6+
location / {
7+
proxy_pass http://localhost:8000;
8+
proxy_set_header Host $host;
9+
proxy_set_header X-Real-IP $remote_addr;
10+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11+
proxy_set_header X-Forwarded-Proto $scheme;
12+
proxy_redirect off;
13+
}
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# sudo nano /etc/nginx/sites-available/pysearch.mallickboy.com
2+
3+
server { # Redirect HTTP traffic to HTTPS
4+
listen 80;
5+
server_name pysearch.mallickboy.com;
6+
return 301 https://$host$request_uri; # Redirect to HTTPS
7+
}
8+
9+
server { # HTTPS Configuration
10+
listen 443 ssl http2;
11+
server_name pysearch.mallickboy.com;
12+
13+
ssl_certificate /etc/letsencrypt/live/pysearch.mallickboy.com/fullchain.pem; # SSL certificate paths
14+
ssl_certificate_key /etc/letsencrypt/live/pysearch.mallickboy.com/privkey.pem;
15+
16+
ssl_protocols TLSv1.2 TLSv1.3; # SSL security settings
17+
ssl_ciphers HIGH:!aNULL:!MD5;
18+
ssl_prefer_server_ciphers on;
19+
20+
location / { # proxy requests to flask app
21+
proxy_pass http://localhost:8000;
22+
proxy_set_header Host $host;
23+
proxy_set_header X-Real-IP $remote_addr;
24+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25+
proxy_set_header X-Forwarded-Proto $scheme;
26+
proxy_redirect off;
27+
}
28+
}

server_setup/pysearch.service

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=Gunicorn instance for PySearch # put it at sudo nano /etc/systemd/system/pysearch.service for gunicorn
3+
After=network.target
4+
5+
# Setup to run gunicorn at system start
6+
7+
[Service]
8+
User=mallickboy
9+
Group=www-data
10+
WorkingDirectory=/home/mallickboy/pysearch
11+
ExecStart=/home/mallickboy/pysearch/pysearch/bin/gunicorn -w 2 -b 0.0.0.0:8000 app:app # 2 workers
12+
13+
# Optional: Standard output/error redirection to logs
14+
StandardOutput=syslog
15+
StandardError=syslog
16+
SyslogIdentifier=gunicorn
17+
18+
[Install]
19+
WantedBy=multi-user.target

server_setup/search.mallickboy.com

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# sudo nano /etc/nginx/sites-available/search.mallickboy.com
2+
3+
server { # Redirect HTTP traffic to HTTPS
4+
listen 80;
5+
server_name search.mallickboy.com;
6+
return 301 https://$host$request_uri; # Redirect to HTTPS
7+
}
8+
9+
server { # HTTPS Configuration
10+
listen 443 ssl http2;
11+
server_name search.mallickboy.com;
12+
13+
ssl_certificate /etc/letsencrypt/live/search.mallickboy.com/fullchain.pem; # SSL certificate paths
14+
ssl_certificate_key /etc/letsencrypt/live/search.mallickboy.com/privkey.pem;
15+
16+
ssl_protocols TLSv1.2 TLSv1.3; # SSL security settings
17+
ssl_ciphers HIGH:!aNULL:!MD5;
18+
ssl_prefer_server_ciphers on;
19+
20+
location / { # proxy requests to flask app
21+
proxy_pass http://localhost:8000;
22+
proxy_set_header Host $host;
23+
proxy_set_header X-Real-IP $remote_addr;
24+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25+
proxy_set_header X-Forwarded-Proto $scheme;
26+
proxy_redirect off;
27+
}
28+
}

0 commit comments

Comments
 (0)