Last active
February 13, 2024 09:35
-
-
Save michalskop/9edee4757545c7d905c4 to your computer and use it in GitHub Desktop.
Setting up an Ubuntu server
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
<VirtualHost *:80> | |
# example of settings for Postgrest API | |
ServerAdmin [email protected] | |
ServerName api.example.com | |
ProxyPreserveHost On | |
# setup the proxy | |
<Proxy *> | |
Order allow,deny | |
Allow from all | |
</Proxy> | |
ProxyPass / http://localhost:3000/ | |
ProxyPassReverse / http://localhost:3000/ | |
</VirtualHost> |
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
# Example of settings for http | |
# note: rename to example.com.conf | |
<VirtualHost *:80> | |
ServerAdmin [email protected] | |
ServerName example.com | |
ServerAlias www.example.com | |
DocumentRoot /var/www/example.com/ | |
ErrorLog /var/log/apache2/example.com-error.log | |
LogLevel warn | |
CustomLog /var/log/apache2/example.com-access.log combined | |
<Directory /> | |
Options +FollowSymLinks -Indexes | |
AllowOverride None | |
Order deny,allow | |
deny from all | |
</Directory> | |
<Directory /var/www/example.com/ > | |
AllowOverride None | |
Order allow,deny | |
allow from all | |
DirectoryIndex index.php index.html | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
# redirect www.example.com to example.com | |
RewriteBase / | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] | |
ErrorDocument 404 /index.php | |
# if the file with the specified name in the browser doesn't exist, or the directory in the browser doesn't exist then procede to the rewrite rule below: | |
# RewriteCond %{REQUEST_FILENAME} !-f | |
# RewriteCond %{REQUEST_FILENAME} !-d | |
# RewriteCond %{REQUEST_URI} !=/favicon.ico | |
# RewriteRule ^(.*)$ index.php?page=$1 [L,QSA] | |
</IfModule> | |
</Directory> | |
<Files favicon.ico> | |
ErrorDocument 404 "The requested file favicon.ico was not found." | |
</Files> | |
</VirtualHost> |
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
# Example of settings for https with Let's encrypt | |
# note: renamed to example.com.conf | |
<VirtualHost *:80> | |
ServerName example.com | |
ServerAlias www.example.com | |
DocumentRoot /var/www/example.com/ | |
<Directory /var/www/example.com/ > | |
AllowOverride None | |
Order allow,deny | |
allow from all | |
DirectoryIndex index.php index.html | |
# redirect to https version | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{SERVER_PORT} ^80$ | |
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] | |
</IfModule> | |
</Directory> | |
</VirtualHost> | |
<VirtualHost *:443> | |
SSLEngine on | |
SSLProtocol all -SSLv2 | |
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM | |
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem | |
ServerAdmin [email protected] | |
ServerName example.com | |
ServerAlias www.example.com | |
DocumentRoot /var/www/example.com/ | |
ErrorLog /var/log/apache2/example.com-error.log | |
LogLevel warn | |
CustomLog /var/log/apache2/example.com-access.log combined | |
<Directory /> | |
Options +FollowSymLinks -Indexes | |
AllowOverride None | |
Order deny,allow | |
deny from all | |
</Directory> | |
<Directory /var/www/example.com/ > | |
AllowOverride None | |
Order allow,deny | |
allow from all | |
DirectoryIndex index.php index.html | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
# redirect www.example.com to example.com | |
RewriteBase / | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
ErrorDocument 404 /index.php | |
# if the file with the specified name in the browser doesn't exist, or the directory in the browser doesn't exist then procede to the rewrite rule below: | |
# RewriteCond %{REQUEST_FILENAME} !-f | |
# RewriteCond %{REQUEST_FILENAME} !-d | |
# RewriteCond %{REQUEST_URI} !=/favicon.ico | |
# RewriteRule ^(.*)$ index.php?page=$1 [L,QSA] | |
</IfModule> | |
</Directory> | |
<Files favicon.ico> | |
ErrorDocument 404 "The requested file favicon.ico was not found." | |
</Files> | |
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem | |
</VirtualHost> |
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
# Example of settings for https using Let's encrypt | |
# note: rename to example.com.conf | |
<VirtualHost *:80> | |
ServerName example.com | |
ServerAlias www.example.com | |
DocumentRoot /var/www/example.com/ | |
<Directory /var/www/example.com/ > | |
AllowOverride None | |
Order allow,deny | |
allow from all | |
DirectoryIndex index.php index.html | |
</Directory> | |
RewriteEngine on | |
RewriteCond %{SERVER_NAME} =example.com [OR] | |
RewriteCond %{SERVER_NAME} =www.example.com | |
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] | |
</VirtualHost> |
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
# not using anymore, switched to postgrest-3000.service | |
# https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04 | |
# postgrest - postgrest job file | |
description "run postgrest" | |
author "Michal Skop <[email protected]>" | |
# Stanzas | |
# | |
# Stanzas control when and how a process is started and stopped | |
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn | |
# When to start the service | |
start on runlevel [2345] | |
# When to stop the service | |
stop on runlevel [016] | |
# Automatically restart process if crashed | |
respawn | |
# Essentially lets upstart know the process will detach itself to the background | |
expect fork | |
# Run before process | |
#pre-start script | |
# [ -d /var/run/myservice ] || mkdir -p /var/run/myservice | |
# echo "Put bash code here" | |
#end script | |
# Start the process | |
exec /opt/postgrest/postgrest /opt/postgrest/postgrest.conf |
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
# postgrest - postgrest job file | |
description "run postgrest" | |
author "Michal Skop <[email protected]>" | |
# Stanzas | |
# | |
# Stanzas control when and how a process is started and stopped | |
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn | |
# When to start the service | |
start on runlevel [2345] | |
# When to stop the service | |
stop on runlevel [016] | |
# Automatically restart process if crashed | |
respawn | |
# Essentially lets upstart know the process will detach itself to the background | |
expect fork | |
# Run before process | |
#pre-start script | |
# [ -d /var/run/myservice ] || mkdir -p /var/run/myservice | |
# echo "Put bash code here" | |
#end script | |
# Start the process | |
exec /opt/postgrest postgres://postgres:example_password@localhost:5432/example_database -p 3000 -a anon --schema public --max-rows 50 --pool 50 -j example_secret |
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
# Postgrest conf file | |
# http://postgrest.com/en/v0.4/admin.html#running-the-server | |
# The standard connection URI format, documented at | |
# https://www.postgresql.org/docs/current/static/libpq-connect.html#AEN45347 | |
db-uri = "postgres://xuser:xpass@xhost:x5432/xdbname" | |
# The name of which database schema to expose to REST clients | |
db-schema = "xapi" | |
# The database role to use when no client authentication is provided. | |
# Can (and probably should) differ from user in db-uri | |
db-anon-role = "xanon" | |
# Number of connections to keep open in PostgREST’s database pool. | |
# Having enough here for the maximum expected simultaneous client | |
# connections can improve performance. | |
# Note it’s pointless to set this higher than the max_connections GUC in your database. | |
db-pool = 50 | |
# Where to bind the PostgREST web server. | |
# server-host = *4 | |
# The port to bind the web server. | |
server-port = 3000 | |
# The secret used to decode JWT tokens clients provide for authentication. | |
# If this parameter is not specified then PostgREST refuses authentication requests. | |
# Choosing a value for this parameter beginning with the at sign such as @filename | |
# loads the secret out of an external file. This is useful for automating deployments. | |
# Note that any binary secrets must be base64 encoded. | |
jwt-secret = "example_secret" | |
# A hard limit to the number of rows PostgREST will fetch from a view, table, or stored procedure. | |
# Limits payload size for accidental or malicious requests. | |
# default: ∞ | |
max-rows = 50 |
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
[Unit] | |
After=postgresql.service | |
[Service] | |
ExecStart=/opt/postgrest/postgrest /opt/postgrest/postgrest-3000.conf | |
[Install] | |
WantedBy=default.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment