Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inspiretk/e39f4b23ffb7e2b4650c68e304b33cdf to your computer and use it in GitHub Desktop.
Save inspiretk/e39f4b23ffb7e2b4650c68e304b33cdf to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script is to setup 2 domains on same server with 1 odoo install
# It will have lets encrypt ssl, www to non www redirect, odoo port 8069 to port 80
# Make sure both domains point to your server ip
# go to your odoo database domain1.com:8069/web/database/selector
# create database domain1_com
# go to your domain2 and do the same eg domain2.com.au:8069/web/database/selector
# create another database domain2_com_au
# Make sure you make a STRONG PASSWORD for Master Password for your databases
# In below script, CHANGE to your domain name all lowercase eg DOMAIN1=YourDomainName.com and DOMAIN2
# go to cd /etc and type ls and see if you can see your odoo conf file, this script has /etc/odoo-server.conf, yours can be different
# if your odoo conf file is different, rename it in the script variables ODOOCFOLDER and ODOOCFILE
# run these commands below with root user, you can disable root user after you're done
# nano nginxresslmulti.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x nginxresslmulti.sh
# ./nginxresslmulti.sh
# (when script is running, press enter to continue, put your important email for ssl renewal notices, 2 for redirect to non www)
DOMAIN1=thuani.com
DOMAIN2=cellardrop.com.au
ODOOCFOLDER=/etc
ODOOCFILE=odoo-server.conf
echo -e "\n---- Update odoo conf file for mutliple database ----"
cd $ODOOCFOLDER
sudo sed -i 's/dbfilter = /dbfilter = ^%h\$/g' $ODOOCFILE
sudo service odoo-server restart
echo -e "\n---- apt-get update and upgrade ----"
cd
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Install nginx, and set up ----"
sudo apt install nginx -y
echo -e "\n---- Setting up basic firewall Nginx Full and OpenSSH ----"
sudo ufw enable
sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'
echo -e "\n---- Setting up nginx conf for your first domain ----"
cd /etc/nginx/sites-available
sudo sed -i '$ d' default
sudo sed -i '$ d' default
sudo sed -i '$ d' default
sudo sed -i 's|# First attempt to serve request as file, then|proxy_pass http://localhost:8069;|g' default
sudo sed -i 's|# as directory, then fall back to displaying a 404.|proxy_http_version 1.1;|g' default
sudo sed -i 's|try_files $uri $uri/ =404;|proxy_set_header Upgrade $http_upgrade;|g' default
sudo sed -i "/proxy_set_header Upgrade \$http_upgrade;/a proxy_set_header Connection 'upgrade';" default
sudo sed -i "/proxy_set_header Connection 'upgrade';/a proxy_set_header Host \$host;" default
sudo sed -i "/proxy_set_header Host \$host;/a proxy_cache_bypass \$http_upgrade;" default
echo -e "\n---- Removing default_server in default nginx file----"
cd /etc/nginx/sites-available
sudo sed -i 's/listen 80 default_server;/listen 80;/g' default
sudo sed -i "s|listen \[::\]:80 default_server;|listen \[::\]:80;|g" default
echo -e "\n---- Rename default nginx file to your domain name and delete enabled default file ----"
cd /etc/nginx/sites-available
sudo cp default $DOMAIN1
sudo rm -v default
cd /etc/nginx/sites-enabled
sudo rm -v default
echo -e "\n---- Create template nginx file called template ----"
cd /etc/nginx/sites-available
sudo cp $DOMAIN1 template
echo -e "\n---- Setting up redirect www to non www and fixing up server name----"
echo -e "\n---- Doing on domain1 ----"
cd /etc/nginx/sites-available
echo "server {" >> $DOMAIN1
echo "listen 80;" >> $DOMAIN1
echo "server_name www.$DOMAIN1;" >> $DOMAIN1
echo "return 301 \$scheme://$DOMAIN1\$request_uri;" >> $DOMAIN1
echo "}" >> $DOMAIN1
sed -i "/server_name _;/c\server_name $DOMAIN1;" $DOMAIN1
sudo service nginx restart
echo -e "\n---- Enable the domains ngix file from available to enable ----"
sudo ln -s /etc/nginx/sites-available/$DOMAIN1 /etc/nginx/sites-enabled/$DOMAIN1
nginx -t
sudo service nginx restart
echo -e "\n---- Installing Lets Encrypt and Setting up SSL on domain1 ----"
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
apt install python-certbot-nginx -y
certbot --nginx -d $DOMAIN1
sudo apt-get install software-properties-common python-software-properties
apt-get install python-certbot-nginx -y
sudo nginx -t
systemctl reload nginx.service
echo -e "\n---- Domain1 setup complete!!! ----"
echo -e "\n---- Setting up domain2 ----"
echo -e "\n---- Create domain2 nginx file from template file ----"
cd /etc/nginx/sites-available
sudo cp template $DOMAIN2
echo -e "\n---- Setting up redirect www to non www and fixing up server name----"
cd /etc/nginx/sites-available
echo "server {" >> $DOMAIN2
echo "listen 80;" >> $DOMAIN2
echo "server_name www.$DOMAIN2;" >> $DOMAIN2
echo "return 301 \$scheme://$DOMAIN2\$request_uri;" >> $DOMAIN2
echo "}" >> $DOMAIN2
sed -i "/server_name _;/c\server_name $DOMAIN2;" $DOMAIN2
sudo service nginx restart
echo -e "\n---- Enable the domains ngix file from available to enable ----"
sudo ln -s /etc/nginx/sites-available/$DOMAIN2 /etc/nginx/sites-enabled/$DOMAIN2
nginx -t
sudo service nginx restart
echo -e "\n---- Setting up SSL on domain2 ----"
certbot --nginx -d $DOMAIN2
sudo nginx -t
systemctl reload nginx.service
echo -e "\n---- EVERYTHING COMPLETED!!! ----"
echo -e "\n---- Both domains: ----"
echo -e "\n---- will push www to non www; ----"
echo -e "\n---- push to https ssl ----"
echo -e "\n---- use default website port 80, so no need to put port number 8069 at the end for odoo ----"
echo -e "\n---- Gooooood Luck to you!!! ----"
#!/bin/bash
# If you ever want to add extra domains, you can just run this script
# Change the DOMAIN2 to your latest domain name
# point your extra domain to your server IP
# activate your url for database selector, and go to it
# oneofyourdomain.com.au/web/database/selector
# create new database with name extradomain_com_au
# log into your server
# nano extradomain.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x extradomain.sh
# ./extradomain.sh
DOMAIN2=extradomain.com.au
echo -e "\n---- Setting up domain2 ----"
echo -e "\n---- Create domain2 nginx file from template file ----"
cd /etc/nginx/sites-available
sudo cp template $DOMAIN2
echo -e "\n---- Setting up redirect www to non www and fixing up server name----"
cd /etc/nginx/sites-available
echo "server {" >> $DOMAIN2
echo "listen 80;" >> $DOMAIN2
echo "server_name www.$DOMAIN2;" >> $DOMAIN2
echo "return 301 \$scheme://$DOMAIN2\$request_uri;" >> $DOMAIN2
echo "}" >> $DOMAIN2
sed -i "/server_name _;/c\server_name $DOMAIN2;" $DOMAIN2
sudo service nginx restart
echo -e "\n---- Enable the domains ngix file from available to enable ----"
sudo ln -s /etc/nginx/sites-available/$DOMAIN2 /etc/nginx/sites-enabled/$DOMAIN2
nginx -t
sudo service nginx restart
echo -e "\n---- Setting up SSL on domain2 ----"
certbot --nginx -d $DOMAIN2
sudo nginx -t
systemctl reload nginx.service
echo -e "\n---- EVERYTHING COMPLETED!!! ----"
echo -e "\n---- New domain: ----"
echo -e "\n---- will push www to non www; ----"
echo -e "\n---- push to https ssl ----"
echo -e "\n---- use default website port 80, so no need to put port number 8069 at the end for odoo ----"
echo -e "\n---- Gooooood Luck to you!!! ----"
# Check your lets encrypt ssl to see if auto renew is working
cd /etc/cron.d
sudo nano certbot
# You should have file in there that shows the cron job for your ssl
# exit the file, now do below command to do a test of renewing your ssl
sudo certbot renew --dry-run
# you should get success message. It will auto run for all your ssl on your server
# to disable url database selector in odoo
# find your odoo conf file, mine's located in /etc. Find your odoo.conf file name, mine's odoo-server.conf
cd /etc
sudo nano odoo-server.conf
# add the below line to disable database selector. Find list_db and change True to False
list_db=False
# restart your odoo, my command is below
sudo service odoo-server restart
# now go to your database url and it should not work
https://thuani.com/web/database/manager
https://thuani.com/web/database/selector
The database manager has been disabled by the administrator
# add sudo user to your server
sudo adduser user
sudo adduser user sudo
# disable root access and ssh password authentication
sudo nano /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
# Secure Shared Memory, and copy paste the command at very end of file
sudo nano /etc/fstab
none /run/shm tmpfs defaults,ro 0 0
# Install Fail2ban, and edit the file
sudo apt-get install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
#Software updates, only security updates is automatically updated
apt install unattended-upgrades
#!/bin/bash
# This script is to setup 1 domains on same server with 1 odoo install
# It will have lets encrypt ssl, www to non www redirect, odoo port 8069 to port 80
# add new domain, non www redirect
# In below script, CHANGE to your domain name all lowercase eg DOMAIN1=YourDomainName.com
# run these commands below with root user, you can disable root user after you're done
# nano addnewdomain.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x addnewdomain.sh
# ./addnewdomain.sh
DOMAIN1=thuani.com
echo -e "\n---- Copy template nginx file to your domain name ----"
cd /etc/nginx/sites-available
sudo cp template $DOMAIN1
cd /etc/nginx/sites-enabled
echo -e "\n---- Create template nginx file called template ----"
cd /etc/nginx/sites-available
sudo cp template $DOMAIN1
echo -e "\n---- Setting up redirect www to non www and fixing up server name----"
echo -e "\n---- Doing on domain1 ----"
cd /etc/nginx/sites-available
echo "server {" >> $DOMAIN1
echo "listen 80;" >> $DOMAIN1
echo "server_name www.$DOMAIN1;" >> $DOMAIN1
echo "return 301 \$scheme://$DOMAIN1\$request_uri;" >> $DOMAIN1
echo "}" >> $DOMAIN1
sed -i "/server_name _;/c\server_name $DOMAIN1;" $DOMAIN1
sudo service nginx restart
echo -e "\n---- Enable the domains ngix file from available to enable ----"
sudo ln -s /etc/nginx/sites-available/$DOMAIN1 /etc/nginx/sites-enabled/$DOMAIN1
nginx -t
sudo service nginx restart
echo -e "\n---- EVERYTHING COMPLETED!!! ----"
echo -e "\n---- Both domains: ----"
echo -e "\n---- will push www to non www; ----"
echo -e "\n---- use default website port 80, so no need to put port number 8069 at the end for odoo ----"
echo -e "\n---- Gooooood Luck to you!!! ----"
#!/bin/bash
# CHANGE to your domain name all lowercase eg DOMAIN=YourDomainName.com
# run these commands below with root user, you can disable root user after you're done
# nano ssl.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x ssl.sh
# ./ssl.sh
# Script will ask: email for your domain name; redirect 1 or 2, select 2 for redirect;
DOMAIN=cellardrop.com.au
echo -e "\n---- Changing odoo port from 8069 to 80 for website ----"
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Setting up nginx ----"
sudo apt install nginx -y
cd /etc/nginx/sites-available
sed -i '$ d' default
sed -i '$ d' default
sed -i '$ d' default
sed -i 's|# First attempt to serve request as file, then|proxy_pass http://localhost:8069;|g' default
sed -i 's|# as directory, then fall back to displaying a 404.|proxy_http_version 1.1;|g' default
sed -i 's|try_files $uri $uri/ =404;|proxy_set_header Upgrade $http_upgrade;|g' default
sed -i "/proxy_set_header Upgrade \$http_upgrade;/a proxy_set_header Connection 'upgrade';" default
sed -i "/proxy_set_header Connection 'upgrade';/a proxy_set_header Host \$host;" default
sed -i "/proxy_set_header Host \$host;/a proxy_cache_bypass \$http_upgrade;" default
sudo nginx -t
systemctl reload nginx.service
echo -e "\n---- Setting up SSL Let's Encrypt ----"
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
apt install python-certbot-nginx -y
sed -i "/server_name _;/c\server_name $DOMAIN;" default
nginx -t
echo -e "\n---- Setting up basic firewall Nginx Full and OpenSSH ----"
ufw enable
ufw allow 'Nginx Full'
ufw allow 'OpenSSH'
echo -e "\n---- Setting up Let's Encrypt Certbot ----"
certbot --nginx -d $DOMAIN
sudo apt-get install software-properties-common python-software-properties
apt-get install python-certbot-nginx -y
echo -e "\n---- Setting up redirect www to non www ----"
echo "server {" >> default
echo "listen 80;" >> default
echo "server_name www.$DOMAIN;" >> default
echo "return 301 \$scheme://$DOMAIN\$request_uri;" >> default
echo "}" >> default
sudo service nginx restart
echo -e "\n---- All done. To check reload your website, should be https, and if you go www. your domain name it redirect to no www. Also do ufw status to see your firewall, and check your nginx cd /etc/nginx/sites-available and nano default to make sure the updates there----"
#!/bin/bash
# CHANGE to your domain name all lowercase eg DOMAIN=YourDomainName.com
# this script is to run AFTER you've done your main domain with first script Auto Setup SSL Lets Encrypt and Port 80 and
# redirect to non www using Ubuntu 18.04
# nano ssldomain.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x ssldomain.sh
# ./ssldomain.sh
# Script will ask: email for your domain name; redirect 1 or 2, select 2 for redirect;
DOMAIN=cellardrop.com.au
echo -e "\n---- Setting up SSL on another domain ----"
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Setting up SSL Let's Encrypt ----"
sed -i "/server_name _;/c\server_name $DOMAIN;" default
nginx -t
systemctl reload nginx.service
echo -e "\n---- Setting up Let's Encrypt Certbot ----"
certbot --nginx -d $DOMAIN
# certbot --nginx -d cellardrop.com.au
echo -e "\n---- Setting up redirect www to non www ----"
echo "server {" >> default
echo "listen 80;" >> default
echo "server_name www.$DOMAIN;" >> default
echo "return 301 \$scheme://$DOMAIN\$request_uri;" >> default
echo "}" >> default
sudo service nginx restart
echo -e "\n---- All done. To check reload your website, should be https, and if you go www. your domain name it redirect to no www. Also do ufw status to see your firewall, and check your nginx cd /etc/nginx/sites-available and nano default to make sure the updates there----"
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
server {
listen 80;
server_name www.cellardrop.com.au;
return 301 $scheme://cellardrop.com.au$request_uri;
}
sudo nano /etc/nginx/sites-available/thuani.com
sudo nano /etc/nginx/sites-available/cellardrop.com.au
sudo ln -s /etc/nginx/sites-available/thuani.com /etc/nginx/sites-enabled/thuani.com
sudo ln -s /etc/nginx/sites-available/cellardrop.com.au /etc/nginx/sites-enabled/cellardrop.com.au
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
grep -r listen /etc/nginx/sites-enabled/*
sudo service nginx restart
systemctl reload nginx.service
sudo systemctl reload nginx
sudo certbot renew --dry-run
https://www.digitalocean.com/community/questions/letsencrypt-for-multiple-domains-on-nginx
sudo systemctl restart odoo11.service
sudo service odoo-server restart
https://www.odoo.com/apps/modules/11.0/letsencrypt/
https://www.odoo.com/apps/modules/11.0/dbfilter_from_header/
https://www.dangtrinh.com/2017/12/how-to-hide-manage-databases-link-from.html
https://www.odoo.com/groups/community-59/community-13332694
odoo.conf
server_wide_modules = web,web_kanban,dbfilter_from_header
proxy_set_header X-Odoo-dbfilter [your filter regex];
dbfilter_from_header
https://apps.odoo.com/apps/modules/11.0/letsencrypt/
sudo apt-get install openssl
sudo pip3 install acme-tiny
sudo pip3 install IPy
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name thuani.com;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/thuani.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/thuani.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = thuani.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name thuani.com;
return 404; # managed by Certbot
}
server {
listen 80;
server_name www.thuani.com;
return 301 $scheme://thuani.com$request_uri;
}
server {
if ($host = thuani.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name thuani.com; # managed by Certbot
return 404; # managed by Certbot
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/cellardrop.com.au/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/cellardrop.com.au/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = cellardrop.com.au) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name cellardrop.com.au;
return 404; # managed by Certbot
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name thuani.com;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/thuani.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/thuani.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = thuani.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name thuani.com;
return 404; # managed by Certbot
}
server {
listen 80;
server_name www.thuani.com;
return 301 $scheme://thuani.com$request_uri;
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name cellardrop.com.au;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
server {
if ($host = thuani.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name cellardrop.com.au; # managed by Certbot
return 404; # managed by Certbot
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/cellardrop.com.au/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/cellardrop.com.au/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = cellardrop.com.au) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name cellardrop.com.au;
return 404; # managed by Certbot
}
server {
listen 80;
server_name www.cellardrop.com.au;
return 301 $scheme://cellardrop.com.au$request_uri;
}
#!/bin/bash
# This script is to setup 1 domains on same server with 1 odoo install
# It will have lets encrypt ssl, www to non www redirect, odoo port 8069 to port 80
# Make sure both domains point to your server ip
# Make sure you make a STRONG PASSWORD for Master Password for your databases
# In below script, CHANGE to your domain name all lowercase eg DOMAIN1=YourDomainName.com
# go to cd /etc and type ls and see if you can see your odoo conf file, this script has /etc/odoo-server.conf, yours can be different
# if your odoo conf file is different, rename it in the script variables ODOOCFOLDER and ODOOCFILE
# run these commands below with root user, you can disable root user after you're done
# nano nginxressl.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x nginxressl.sh
# ./nginxressl.sh
# (when script is running, press enter to continue, put your important email for ssl renewal notices, 2 for redirect to non www)
DOMAIN1=thuani.com
ODOOCFOLDER=/etc
ODOOCFILE=odoo-server.conf
echo -e "\n---- Update odoo conf file for mutliple database ----"
cd $ODOOCFOLDER
sudo sed -i 's/dbfilter = /dbfilter = ^%h\$/g' $ODOOCFILE
sudo service odoo-server restart
echo -e "\n---- apt-get update and upgrade ----"
cd
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Install nginx, and set up ----"
sudo apt install nginx -y
echo -e "\n---- Setting up basic firewall Nginx Full and OpenSSH ----"
sudo ufw enable
sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'
echo -e "\n---- Setting up nginx conf for your first domain ----"
cd /etc/nginx/sites-available
sudo sed -i '$ d' default
sudo sed -i '$ d' default
sudo sed -i '$ d' default
sudo sed -i 's|# First attempt to serve request as file, then|proxy_pass http://localhost:8069;|g' default
sudo sed -i 's|# as directory, then fall back to displaying a 404.|proxy_http_version 1.1;|g' default
sudo sed -i 's|try_files $uri $uri/ =404;|proxy_set_header Upgrade $http_upgrade;|g' default
sudo sed -i "/proxy_set_header Upgrade \$http_upgrade;/a proxy_set_header Connection 'upgrade';" default
sudo sed -i "/proxy_set_header Connection 'upgrade';/a proxy_set_header Host \$host;" default
sudo sed -i "/proxy_set_header Host \$host;/a proxy_cache_bypass \$http_upgrade;" default
echo -e "\n---- Removing default_server in default nginx file----"
cd /etc/nginx/sites-available
sudo sed -i 's/listen 80 default_server;/listen 80;/g' default
sudo sed -i "s|listen \[::\]:80 default_server;|listen \[::\]:80;|g" default
echo -e "\n---- Rename default nginx file to your domain name and delete enabled default file ----"
cd /etc/nginx/sites-available
sudo cp default $DOMAIN1
cd /etc/nginx/sites-enabled
echo -e "\n---- Create template nginx file called template ----"
cd /etc/nginx/sites-available
sudo cp $DOMAIN1 template
echo -e "\n---- Setting up redirect www to non www and fixing up server name----"
echo -e "\n---- Doing on domain1 ----"
cd /etc/nginx/sites-available
echo "server {" >> $DOMAIN1
echo "listen 80;" >> $DOMAIN1
echo "server_name www.$DOMAIN1;" >> $DOMAIN1
echo "return 301 \$scheme://$DOMAIN1\$request_uri;" >> $DOMAIN1
echo "}" >> $DOMAIN1
sed -i "/server_name _;/c\server_name $DOMAIN1;" $DOMAIN1
sudo service nginx restart
echo -e "\n---- Enable the domains ngix file from available to enable ----"
sudo ln -s /etc/nginx/sites-available/$DOMAIN1 /etc/nginx/sites-enabled/$DOMAIN1
nginx -t
sudo service nginx restart
echo -e "\n---- EVERYTHING COMPLETED!!! ----"
echo -e "\n---- Both domains: ----"
echo -e "\n---- will push www to non www; ----"
echo -e "\n---- push to https ssl ----"
echo -e "\n---- use default website port 80, so no need to put port number 8069 at the end for odoo ----"
echo -e "\n---- Gooooood Luck to you!!! ----"
#!/bin/bash
# CHANGE to your domain name all lowercase eg DOMAIN=YourDomainName.com
# run these commands below with root user, you can disable root user after you're done
# nano nginxre.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x nginxre.sh
# ./nginxre.sh
DOMAIN=cellardrop.com.au
echo -e "\n---- Changing odoo port from 8069 to 80 for website ----"
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Setting up nginx ----"
sudo apt install nginx -y
cd /etc/nginx/sites-available
echo -e "\n---- Setting up basic firewall Nginx Full and OpenSSH ----"
ufw enable
ufw allow 'Nginx Full'
ufw allow 'OpenSSH'
sed -i '$ d' default
sed -i '$ d' default
sed -i '$ d' default
sed -i 's|# First attempt to serve request as file, then|proxy_pass http://localhost:8069;|g' default
sed -i 's|# as directory, then fall back to displaying a 404.|proxy_http_version 1.1;|g' default
sed -i 's|try_files $uri $uri/ =404;|proxy_set_header Upgrade $http_upgrade;|g' default
sed -i "/proxy_set_header Upgrade \$http_upgrade;/a proxy_set_header Connection 'upgrade';" default
sed -i "/proxy_set_header Connection 'upgrade';/a proxy_set_header Host \$host;" default
sed -i "/proxy_set_header Host \$host;/a proxy_cache_bypass \$http_upgrade;" default
sudo nginx -t
systemctl reload nginx.service
sudo ln -s /etc/nginx/sites-available/thuani.com /etc/nginx/sites-enabled/thuani.com
sudo ln -s /etc/nginx/sites-available/cellardrop.com.au /etc/nginx/sites-enabled/cellardrop.com.au
tail -20 /var/log/nginx/access.log
tail -20 /var/log/nginx/error.log;
remove default_server in listen:80 and listen [::]
cd /etc/nginx/conf.d
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/example.com.conf
echo -e "\n---- Setting up redirect www to non www ----"
echo "server {" >> default
echo "listen 80;" >> default
echo "server_name www.$DOMAIN;" >> default
echo "return 301 \$scheme://$DOMAIN\$request_uri;" >> default
echo "}" >> default
sudo service nginx restart
echo -e "\n---- All done. To check reload your website, should be https, and if you go www. your domain name it redirect to no www. Also do ufw status to see your firewall, and check your nginx cd /etc/nginx/sites-available and nano default to make sure the updates there----"
##### misc stuff ####
systemctl status nginx
Referene: https://www.youtube.com/watch?v=CyYfdhESYRI
sudo apt install nginx -y
cd /etc/nginx/sites-available
sudo nano default
put these in location [or delete all text and copy paste file: the sudo nano default copy paste this file to your default file]
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
sudo nginx -t
systemctl reload nginx.service
sudo systemctl stop nginx
sudo systemctl start nginx
sudo service nginx restart
[nginx commands: sudo systemctl stop nginx; sudo systemctl start nginx; sudo systemctl restart nginx; sudo systemctl reload nginx; sudo systemctl disable nginx; sudo systemctl enable nginx]
https://www.youtube.com/watch?v=7bHSUCKt3SE
sudo apt-get install software-properties-common -y
#add-apt-repository ppa:certbot/certbot
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
apt install python-certbot-nginx -y
nano default
[change server_name to server_name thuani.com;
nginx -t
ufw status
ufw allow 'Nginx Full'
ufw enable
ufw allow 'OpenSSH'
ufw status
certbot --nginx -d thuani.com
sudo apt-get install software-properties-common python-software-properties
apt-get install python-certbot-nginx -y
https://itsybitsybytes.com/how-to-redirect-www-to-non-www-with-nginx-ubuntu-digitalocean/
redirect www to non www [put server at end of default file]
sudo nano default
server {
listen 80;
server_name www.thuani.com;
return 301 $scheme://thuani.com$request_uri;
}
sudo service nginx restart
sed -e "|test message1|a\\
'testing testing'" < data
sed '|proxy_set_header Upgrade $http_upgrade;| a <LINE-TO-BE-ADDED>' FILE.txt
sed '/PATTERN/ a <LINE-TO-BE-ADDED>' FILE.txt
sed -e "/test message1/a\\
'testing testing'" < data
sed -i 's|/home/saeid/public_html|/home/saeid/www/domain.com/html|g' file
p
proxy_cache_bypass $http_upgrade;
sudo nano default
seq 15 > test1.txt
ex test1.txt << EOEX
/^7/,/^9/c
abcd
123
.xyz
hfr4
.
w!
q
EOEX
cat test1.txt
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
#!/bin/bash
# run these commands below with root user, you can disable root user after you're done
# nano ssl.sh
# Copy everything in this script and paste it in, save file and exit
# chmod +x ssl.sh
# ./ssl.sh
# Script will ask: email for your domain name; redirect 1 or 2, select 2 for redirect;
echo -e "\n---- Changing odoo port from 8069 to 80 for website ----"
sudo apt-get update
sudo apt-get upgrade -y
echo -e "\n---- Setting up nginx ----"
sudo apt install nginx -y
cd /etc/nginx/sites-available
sed -i '$ d' default
sed -i '$ d' default
sed -i '$ d' default
sed -i 's|# First attempt to serve request as file, then|proxy_pass http://localhost:8069;|g' default
sed -i 's|# as directory, then fall back to displaying a 404.|proxy_http_version 1.1;|g' default
sed -i 's|try_files $uri $uri/ =404;|proxy_set_header Upgrade $http_upgrade;|g' default
sed -i "/proxy_set_header Upgrade \$http_upgrade;/a proxy_set_header Connection 'upgrade';" default
sed -i "/proxy_set_header Connection 'upgrade';/a proxy_set_header Host \$host;" default
sed -i "/proxy_set_header Host \$host;/a proxy_cache_bypass \$http_upgrade;" default
sudo nginx -t
systemctl reload nginx.service
echo -e "\n---- Setting up SSL Let's Encrypt ----"
sudo apt-get install software-properties-common -y
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
apt install python-certbot-nginx -y
sed -i '/server_name _;/c\server_name thuani.com;' default
nginx -t
echo -e "\n---- Setting up basic firewall Nginx Full and OpenSSH ----"
ufw enable
ufw allow 'Nginx Full'
ufw allow 'OpenSSH'
echo -e "\n---- Setting up Let's Encrypt Certbot ----"
ufw enable
certbot --nginx -d thuani.com
sudo apt-get install software-properties-common python-software-properties
apt-get install python-certbot-nginx -y
echo -e "\n---- Setting up redirect www to non www ----"
echo "server {" >> default
echo "listen 80;" >> default
echo "server_name www.thuani.com;" >> default
echo "return 301 $scheme://thuani.com$request_uri;" >> default
echo "}" >> default
sudo service nginx restart
echo -e "\n---- All done. To check reload your website, should be https, and if you go www. your domain name it redirect to no www. Also do ufw status to see your firewall, and check your nginx cd /etc/nginx/sites-available and nano default to make sure the updates there----"
########################### BOTTOM JUST MISC COPY PASTE DATA USE AS REFERENCE ##########################
upstream odoo {
server 127.0.0.1:8069;
}
server {
listen 443 default;
server_name www.thuani.com;
access_log /var/log/nginx/oddo.access.log;
error_log /var/log/nginx/oddo.error.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.thuani.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.thuani.com/privkey.pem;
keepalive_timeout 60;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location / {
proxy_pass http://odoo;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
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 https;
}
location ~* /web/static/ {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo;
}
}
server {
listen 80;
server_name www.thuani.com;
add_header Strict-Transport-Security max-age=2592000;
rewrite ^/.*$ https://$host$request_uri? permanent;
}
sudo ln -s /etc/nginx/sites-available/thuani.conf /etc/nginx/sites-enabled/thuani.conf
sudo systemctl reload nginx
nginx ssl ubuntu 18.04:
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
sudo ufw app list
systemctl status nginx
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
apt install curl -y
curl -4 thuani.com
sudo nano /etc/nginx/sites-available/thuani.com
server {
listen 80;
listen [::]:80;
root /odoo/odoo-server/addons/web/static;
index index.html index.htm index.nginx-debian.html;
server_name thuani.com www.thuani.com;
location / {
try_files $uri $uri/ =404;
}
}
sudo ln -s /etc/nginx/sites-available/thuani.com /etc/nginx/sites-enabled/
sudo nano /etc/nginx/nginx.conf
https://linuxize.com/post/secure-nginx-with-let-s-encrypt-on-ubuntu-18-04/
sudo apt install certbot -y
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
sudo nano /etc/nginx/sites-enabled/thuani.com
# Odoo servers
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat {
server 127.0.0.1:8072;
}
# HTTP -> HTTPS
server {
listen 80;
server_name www.thuani.com thuani.com;
include snippets/letsencrypt.conf;
return 301 https://thuani.com$request_uri;
}
# WWW -> NON WWW
server {
listen 443 ssl http2;
server_name www.thuani.com;
ssl_certificate /etc/letsencrypt/live/thuani.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/thuani.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/thuani.com/chain.pem;
include snippets/ssl.conf;
return 301 https://thuani.com$request_uri;
}
server {
listen 443 ssl http2;
server_name thuani.com;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Proxy headers
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
# SSL parameters
ssl_certificate /etc/letsencrypt/live/thuani.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/thuani.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/thuani.com/chain.pem;
include snippets/ssl.conf;
# log files
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Handle longpoll requests
location /longpolling {
proxy_pass http://odoochat;
}
# Handle / requests
location / {
proxy_redirect off;
proxy_pass http://odoo;
}
# Cache static files
location ~* /web/static/ {
proxy_cache_valid 200 90m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo;
}
# Gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
https://www.youtube.com/watch?v=7bHSUCKt3SE
Flush ip tables
iptables-save | awk '/^[*]/ { print $1 }
/^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
/COMMIT/ { print $0; }' | iptables-restore
sudo iptables -t nat -L -n -v
iptables-save > /etc/iptables/rules.v4
sed "/'test message1'/a 'testing testing'"
sed -e "/proxy_set_header Upgrade/a\\proxy_set_header Connection 'upgrade';" < default
sed "/\proxy_set_header Upgrade $http_upgrade;\/a proxy_set_header Connection 'upgrade';" default
sed '/\[option\]/a Hello World' input
proxy_set_header Connection 'upgrade';
sed "/proxy_set_header Upgrade $http_upgrade;/ a " default
sed "/proxy_set_header Connection 'upgrade';/ a proxy_set_header Host $host;" default
sed "/proxy_set_header Host $host;/ a proxy_cache_bypass $http_upgrade;" default
sed -i "/proxy_set_header Upgrade /a proxy_set_header Connection 'upgrade';" default
sed "/proxy_set_header Upgrade $http_upgrade;/a proxy_set_header Connection 'upgrade';" default
awk '/proxy_set_header Upgrade $http_upgrade;/{print;print "proxy_set_header Connection 'upgrade';";next}1' default
awk '/Fedora/{print;print "Cygwin";next}1' file
#!/usr/bin/bash
while read line
do
echo $line | grep -q "proxy_set_header Upgrade $http_upgrade;"
[ $? -eq 0 ] && echo "Cygwin"
echo $line
done < default
===================================
https://unix.stackexchange.com/questions/303644/how-can-i-use-sed-or-ex-to-replace-a-block-multi-line-code-with-new-block-of-t
$ seq 8 | sed '/3/,/5/{/5/ s/.*/New Code/; t; d}'
1
2
New Code
6
7
8
seq 8 | sed '/3/,/5/{/5/ s/.*/New Code/; t; d}'
sed -i.bak '/3/,/5/{/5/ s/.*/New Code/; t; d}' file
sed -i 's/^acl verizonfios.*/acl verizonfios src 202.1.2.3/' /etc/squid/squid.con
https://www.youtube.com/watch?v=GgLKjT2jGP4
sed -i.bak '/# First attempt to serve request as file/,/}/{/5/ s/.*/first line/
/second line/
/third line/; t; d}' test.txt
sed -i.bak '/# First attempt to serve request as file/,/}/{/5/ s/.*/third line/; t; d}' test.txt
cd /etc/nginx/sites-available
sudo nano default
sudo nano test.txt
sed -i.bak '/# First attempt to serve request as file/,/404/{/404/ s/.*/proxy_pass http://localhost:8069; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;/; t; d}' test.txt
sed -i.bak '/# First attempt to serve request as file/,/404;/{/404;/ s/.*/ proxy_pass http://localhost:8069; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;/; t; d}'
##### misc stuff below ####
systemctl status nginx
tail -20 /var/log/nginx/access.log
tail -20 /var/log/nginx/error.log;
@inspiretk
Copy link
Author

inspiretk commented Aug 8, 2018

These scripts work: A1 SCRIPT nginxresslmulti WORKING nginx non www ssl 2 domain; and
A2 Script extradomain WORKING nginx non www ssl Extra Domain

Tested with Ubuntu 18.04. Odoo 11 Community Edition.

  • A1 SCRIPT nginxresslmulti WORKING nginx non www ssl 2 domain: Used to setup 2 domains on 1 odoo install.
    If you want extra domains after, you use A2 Script extradomain WORKING nginx non www ssl Extra Domain.

Use only Auto Setup SSL Lets Encrypt and Port 80 and redirect to non www using Ubuntu 18.04. Ignore the rest as they're just misc notes.
Make sure you change to your domain name, and you log in as root. Make sure you disable root access when you're done for security purposes (if this is your normal option)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment