Last active
July 11, 2020 00:48
-
-
Save yasmanycastillo/c6ae817e46044799adf127570426ec13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OE_USER="odoo" | |
OE_PORT="8069" | |
WEBSITE_NAME="_" | |
LONGPOLLING_PORT="8072" | |
ADMIN_EMAIL="test@example.com" | |
OE_CONFIG="${OE_USER}-server" | |
#-------------------------------------------------- | |
# Install Nginx if needed | |
#-------------------------------------------------- | |
echo -e "\n---- Installing and setting up Nginx ----" | |
sudo apt install nginx -y | |
cat <<EOF > ~/odoo | |
server { | |
listen 80; | |
# set proper server name after domain set | |
server_name $WEBSITE_NAME; | |
# Add Headers for odoo proxy mode | |
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; | |
add_header X-Frame-Options "SAMEORIGIN"; | |
add_header X-XSS-Protection "1; mode=block"; | |
proxy_set_header X-Client-IP \$remote_addr; | |
proxy_set_header HTTP_X_FORWARDED_HOST \$remote_addr; | |
# odoo log files | |
access_log /var/log/nginx/$OE_USER-access.log; | |
error_log /var/log/nginx/$OE_USER-error.log; | |
# increase proxy buffer size | |
proxy_buffers 16 64k; | |
proxy_buffer_size 128k; | |
proxy_read_timeout 900s; | |
proxy_connect_timeout 900s; | |
proxy_send_timeout 900s; | |
# force timeouts if the backend dies | |
proxy_next_upstream error timeout invalid_header http_500 http_502 | |
http_503; | |
types { | |
text/less less; | |
text/scss scss; | |
} | |
# enable data compression | |
gzip on; | |
gzip_min_length 1100; | |
gzip_buffers 4 32k; | |
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript application/pdf image/jpeg image/png; | |
gzip_vary on; | |
client_header_buffer_size 4k; | |
large_client_header_buffers 4 64k; | |
client_max_body_size 0; | |
location / { | |
proxy_pass http://127.0.0.1:$OE_PORT; | |
# by default, do not forward anything | |
proxy_redirect off; | |
} | |
location /longpolling { | |
proxy_pass http://127.0.0.1:$LONGPOLLING_PORT; | |
} | |
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires 2d; | |
proxy_pass http://127.0.0.1:$OE_PORT; | |
add_header Cache-Control "public, no-transform"; | |
} | |
# cache some static data in memory for 60mins. | |
location ~ /[a-zA-Z0-9_-]*/static/ { | |
proxy_cache_valid 200 302 60m; | |
proxy_cache_valid 404 1m; | |
proxy_buffering on; | |
expires 864000; | |
proxy_pass http://127.0.0.1:$OE_PORT; | |
} | |
} | |
EOF | |
sudo mv ~/odoo /etc/nginx/sites-available/ | |
sudo ln -s /etc/nginx/sites-available/odoo /etc/nginx/sites-enabled/odoo | |
sudo rm /etc/nginx/sites-enabled/default | |
sudo service nginx reload | |
sudo su root -c "printf 'proxy_mode = True\n' >> /etc/${OE_CONFIG}.conf" | |
echo "Done! The Nginx server is up and running. Configuration can be found at /etc/nginx/sites-available/odoo" | |
#-------------------------------------------------- | |
# Enable ssl with certbot | |
#-------------------------------------------------- | |
sudo add-apt-repository ppa:certbot/certbot -y && sudo apt-get update -y | |
sudo apt-get install python-certbot-nginx -y | |
sudo certbot --nginx -d $WEBSITE_NAME --noninteractive --agree-tos --email '$ADMIN_EMAIL' --redirect | |
sudo service nginx reload | |
echo "SSL/HTTPS is enabled!" | |
echo "Nginx configuration file: /etc/nginx/sites-available/odoo" | |
echo "-----------------------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment