Skip to content

Commit

Permalink
chore: 🤖 update proxy server setup details
Browse files Browse the repository at this point in the history
  • Loading branch information
heldrida committed Jun 10, 2024
1 parent c9c19e1 commit 93dd6f0
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 15 deletions.
67 changes: 64 additions & 3 deletions Services/ProxyServer/DeprecatedContentSitesRedirect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ apt install certbot python3-certbot-nginx
5) Generate the certificates

Generate the certificates by following the prompts to complete the SSL setup use the team admin email address during registration.

Run the command for each domain.

```sh
certbot certonly \
--nginx \
--standalone \
-d blog.fleek.xyz \
-d docs.fleek.xyz \
-d <TEST-URL>
-d <DOMAIN>
```

Expect a response similar to the following for each domain blog and docs.
Expand Down Expand Up @@ -91,6 +91,67 @@ nginx -t
systemctl reload nginx
```

10) Verify

Run the openssl command for the domain.

```sh
openssl s_client -connect <DOMAIN>:443 -servername <DOMAIN>
```

You should find.

```sh
-----END CERTIFICATE-----
subject=CN=<DOMAIN>
issuer=C=US, O=Let's Encrypt, CN=R11
---
```
## Enable njs module
The original URL are case-sensitive and we'd like to normalize it as lowercase. For that we can use the njs module to allow us to compute with javascript.

Edit the nginx.conf file and load the module outside the http block.

```sh
load_module modules/ngx_http_js_module.so;
http {
...
}
```

Include the path where the njs script is going to be located, import the script and set the utility variable.

```sh
js_path "/etc/nginx/njs/";
js_import utils from lowercase.js;
js_set $lc utils.lowercase;
```

Create the directory njs

```sh
mkdir /etc/nginx/njs
```

Create the script file

```sh
touch /etc/nginx/njs/lowercase.js
```

Open the file and put the content

```sh
function lowercase(r) {
var originalValue = r.uri.split(/^\/(docs|post)(.*)$/)[2];
var lowercased = originalValue.toLowerCase();
return lowercased;
}
```

## Usage

1) Open the Nginx configuration file that is typically located at `/etc/nginx/nginx.conf` or within the `/etc/nginx/sites-available` directory
Expand Down
42 changes: 30 additions & 12 deletions Services/ProxyServer/DeprecatedContentSitesRedirect/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
server {
set $old_blog_host "blog.fleek.xyz";
set $redirect_url "https://fleek.xyz";

listen 443 ssl;
server_name $old_blog_host;
server_name blog.fleek.xyz;

resolver 8.8.8.8;

ssl_certificate /etc/letsencrypt/live/blog.fleek.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.fleek.xyz/privkey.pem;

include /etc/nginx/shared/locations;
location ~* ^/post/(builders-[a-z0-9-]+|build3rs-[a-z0-9-]+|guides-[a-z0-9-]+|troubleshooting-[a-z0-9-]+|wordpress-[a-z0-9-]+|thegraph-[a-z0-9-]+|hosting-on-ipfs-[a-z0-9-]+|storing-nft-[a-z0-9-]+|decentralized-databases-[a-z0-9-]+|web3-stack-[a-z0-9-]+|fleek-domain-error-handling-[a-z0-9-]+|ipfs-resolving-tips-[a-z0-9-]+|ipfs-importance-and-value-[a-z0-9-]+|fleekco-users-[a-z0-9-]+)$ {
return 301 https://fleek.xyz/guides/$lc;
}

location ~* ^/post/(best-javascript-frameworks-for-web-apps-[a-z0-9-]+|next-js-and-app-dev-[a-z0-9-]+|next-js-node-js-react-[a-z0-9-]+|what-is-bandwidth-[a-z0-9-]+)$ {
return 301 https://fleek.xyz/blog/learn/$lc;
}

location ~* ^/post/(.*-guide/?)$ {
return 301 https://fleek.xyz/guides/$lc;
}

location ~* ^/post/(.*)$ {
return 301 https://fleek.xyz/blog/announcements/$lc;
}

location / {
return 301 https://fleek.xyz/blog;
}
}

server {
set $old_docs_host "docs.fleek.xyz";
set $redirect_url "https://fleek.xyz";

listen 443 ssl;
server_name $old_docs_host;
server_name docs.fleek.xyz;

resolver 8.8.8.8;

ssl_certificate /etc/letsencrypt/live/docs.fleek.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/docs.fleek.xyz/privkey.pem;

include /etc/nginx/shared/locations;
location ~* ^/docs/(.*)$ {
return 301 https://fleek.xyz/docs/$lc;
}

location / {
return 301 https://fleek.xyz/docs;
}
}

server {
set $test_host "nginx-ubuntu-redirect-proxy.flkservices.io";
set $redirect_url "https://fleek.xyz";
set $redirect_url "https://fleek-xyz-staging.on-fleek.app";

listen 443 ssl;
server_name $test_host;
Expand All @@ -40,5 +58,5 @@ server {
ssl_certificate /etc/letsencrypt/live/nginx-ubuntu-redirect-proxy.flkservices.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nginx-ubuntu-redirect-proxy.flkservices.io/privkey.pem;

include /etc/nginx/shared/locations;
// Locations...
}

0 comments on commit 93dd6f0

Please sign in to comment.