Kselax.ru

Hacker Kselax – the best hacker in the world

Menu
  • Blog
  • Contacts
  • wp plugin generator
  • English
    • Русский
Menu

Nginx

Posted on 20 January, 201924 June, 2019 by admin

Creating a server block for node.js

create a directory

1
2
sudo mkdir -p /var/www/fl.com
sudo chown -R $USER:$USER /var/www/fl.com

 

create a server block config file for fl.com

1
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/fl.com

 

add there is the next config /etc/nginx/sites-available/fl.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
upstream fl-com-app {
ip_hash;
server 127.0.0.1:3002;
}
 
server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/snakeoil.conf;
root /var/www/fl.com;
index index.html;
server_name fl.com www.fl.com;
location / {
proxy_pass http://fl-com-app;
}
}
 
server {
listen 80;
listen [::]:80;
server_name fl.com www.fl.com;
return 301 https://$host$request_uri;
}

create a symbolic link

1
sudo ln -s /etc/nginx/sites-available/fl.com /etc/nginx/sites-enabled/

 

test configuration

1
sudo nginx -t

 

then restart nginx

1
sudo systemctl restart nginx

 

add the  fl.com to the /etc/hosts

1
127.0.0.1 fl.com

 

Open in browser https://fl.com and you’ll get your created server block. There we’ll be an error 502 or whatever. the fl.com will redirect everything to the 3002 port, so you have to run some server on this port.

 

#Set up the servers for React with GraphQL

In this case, I’m going to create two server blocks development.com and production.com.

The development.com redirects users to two different hosts http://127.0.0.1:3000 to create-react-app and http://127.0.0.1:3002 to the nodemon server.

The production.com redirects users only to the one host, afterward routing is done by using express

Here are configs:

/etc/nginx/sites-available/development.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
upstream development-com-3000 {
ip_hash;
server 127.0.0.1:3000;
}
 
upstream development-com-3002 {
ip_hash;
server 127.0.0.1:3002;
}
 
server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/snakeoil.conf;
root /var/www/development.com;
index index.html;
server_name development.com www.development.com;
location / {
proxy_pass http://development-com-3000;
}
location ~ /graphql/* {
proxy_pass http://development-com-3002;
}
}
 
server {
listen 80;
  listen [::]:80;
server_name development.com www.development.com;
return 301 https://$host$request_uri;
}

 

/etc/nginx/sites-available/development.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
upstream production-com-3002 {
ip_hash;
server 127.0.0.1:3002;
}
 
server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/snakeoil.conf;
root /var/www/production.com;
index index.html;
server_name production.com www.production.com;
location / {
proxy_pass http://production-com-3002;
}
}
 
server {
listen 80;
  listen [::]:80;
server_name production.com www.production.com;
return 301 https://$host$request_uri;
}

 

How to turn on gzip in nginx

How to enable/disable gzip compression in nginx on a Plesk server

You can add this code in the /etc/nginx/sites-available/default

1
2
3
4
5
6
7
8
server {
        gzip on;
        gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
        gzip_proxied any;
        gzip_comp_level 5;
        gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/rss+xml text/javascript image/x-icon image/bmp image/svg+xml;
        gzip_vary on;
}

and then

1
sudo nginx -t

1
sudo systemctl restart nginx

that’s it

 

the end

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • bash (1)
  • English (9)
  • JavaScript (4)
  • node.js (22)
  • photoshop (1)
  • php (3)
  • React (9)
  • sclerotic (6)
  • Ubuntu (10)
  • Uncategorized (13)
  • Wordpress (1)

Tags

Ajax apache2 automation bash chrome-extension command line editor ejs email English English-grammar framework functions git graphql handlebars hybrid app installation javascript js linux newbie node.js node.js javascript nodemailer npm objects Performance php phpmyadmin playonlinux promise rabbitmq React react-router redis reverse-proxy session shell socket.io sublime text 3 time zones ubuntu unity webpack

Recent Comments

  • damien on How to install npm and nodejs the latest versions on ubuntu
  • Cam on How to install npm and nodejs the latest versions on ubuntu
  • Pierre on socket.io with apache as a reverse proxy on the CentOS
  • admin on How to use react-router with a few languages
  • admin on How to install npm and nodejs the latest versions on ubuntu
©2021 Kselax.ru Theme by ThemeGiant