Skip to content

Instantly share code, notes, and snippets.

@sguter90
Last active July 8, 2022 02:09
Show Gist options
  • Save sguter90/1dfc6a3e2a796b56238fdc35af210997 to your computer and use it in GitHub Desktop.
Save sguter90/1dfc6a3e2a796b56238fdc35af210997 to your computer and use it in GitHub Desktop.
Beyond Code - Expose - systemd & nginx reverse proxy setup
<?php
return [
/*
|--------------------------------------------------------------------------
| Host
|--------------------------------------------------------------------------
|
| The expose server to connect to. By default, expose is using the free
| sharedwithexpose.com server, offered by Beyond Code. You will need a free
| Beyond Code account in order to authenticate with the server.
| Feel free to host your own server and change this value.
|
*/
'host' => 'sharedwithexpose.com',
/*
|--------------------------------------------------------------------------
| Port
|--------------------------------------------------------------------------
|
| The port that expose will try to connect to. If you want to bypass
| firewalls and have proper SSL encrypted tunnels, make sure to use
| port 443 and use a reverse proxy for Expose.
|
| The free default server is already running on port 443.
|
*/
'port' => 443,
/*
|--------------------------------------------------------------------------
| Auth Token
|--------------------------------------------------------------------------
|
| The global authentication token to use for the expose server that you
| are connecting to. You can let expose automatically update this value
| for you by running
|
| > expose token YOUR-AUTH-TOKEN
|
*/
'auth_token' => '',
/*
|--------------------------------------------------------------------------
| Default TLD
|--------------------------------------------------------------------------
|
| The default TLD to use when sharing your local sites. Expose will try
| to look up the TLD if you are using Laravel Valet automatically.
| Otherwise you can specify it here manually.
|
*/
'default_tld' => 'test',
/*
|--------------------------------------------------------------------------
| Maximum Logged Requests
|--------------------------------------------------------------------------
|
| The maximum number if requests to keep in memory when inspecting your
| requests and responses in the local dashboard.
|
*/
'max_logged_requests' => 25,
/*
|--------------------------------------------------------------------------
| Maximum Allowed Memory
|--------------------------------------------------------------------------
|
| The maximum memory allocated to the expose process.
|
*/
'memory_limit' => '128M',
/*
|--------------------------------------------------------------------------
| Skip Response Logging
|--------------------------------------------------------------------------
|
| Sometimes, some responses don't need to be logged. Some are too big,
| some can't be read (like compiled assets). This configuration allows you
| to be as granular as you wish when logging the responses.
|
| If you run constantly out of memory, you probably need to set some of these up.
|
| Keep in mind, by default, BINARY requests/responses are not logged.
| You do not need to add video/mp4 for example to this list.
|
*/
'skip_body_log' => [
/**
* | Skip response logging by HTTP response code. Format: 4*, 5*.
*/
'status' => [
// "4*"
],
/**
* | Skip response logging by HTTP response content type. Ex: "text/css".
*/
'content_type' => [
//
],
/**
* | Skip response logging by file extension. Ex: ".js.map", ".min.js", ".min.css".
*/
'extension' => [
'.js.map',
'.css.map',
],
/**
* | Skip response logging if response size is greater than configured value.
* | Valid suffixes are: B, KB, MB, GB.
* | Ex: 500B, 1KB, 2MB, 3GB.
*/
'size' => '1MB',
],
'admin' => [
/*
|--------------------------------------------------------------------------
| Database
|--------------------------------------------------------------------------
|
| The SQLite database that your expose server should use. This database
| will hold all users that are able to authenticate with your server,
| if you enable authentication token validation.
|
*/
'database' => getcwd().DIRECTORY_SEPARATOR.'expose.db', // CHANGED
//'database' => ':memory:',
/*
|--------------------------------------------------------------------------
| Validate auth tokens
|--------------------------------------------------------------------------
|
| By default, once you start an expose server, anyone is able to connect to
| it, given that they know the server host. If you want to only allow the
| connection from users that have valid authentication tokens, set this
| setting to true. You can also modify this at runtime in the server
| admin interface.
|
*/
'validate_auth_tokens' => true, // CHANGED
/*
|--------------------------------------------------------------------------
| Maximum connection length
|--------------------------------------------------------------------------
|
| If you want to limit the amount of time that a single connection can
| stay connected to the expose server, you can specify the maximum
| connection length in minutes here. A maximum length of 0 means that
| clients can stay connected as long as they want.
|
*/
'maximum_connection_length' => 0,
/*
|--------------------------------------------------------------------------
| Subdomain
|--------------------------------------------------------------------------
|
| This is the subdomain that your expose admin dashboard will be available at.
| The given subdomain will be reserved, so no other tunnel connection can
| request this subdomain for their own connection.
|
*/
'subdomain' => 'admin', // CHANGED
/*
|--------------------------------------------------------------------------
| Subdomain Generator
|--------------------------------------------------------------------------
|
| This is the subdomain generator that will be used, when no specific
| subdomain was provided. The default implementation simply generates
| a random string for you. Feel free to change this.
|
*/
'subdomain_generator' => \App\Server\SubdomainGenerator\RandomSubdomainGenerator::class,
/*
|--------------------------------------------------------------------------
| Users
|--------------------------------------------------------------------------
|
| The admin dashboard of expose is protected via HTTP basic authentication
| Here you may add the user/password combinations that you want to
| accept as valid logins for the dashboard.
|
*/
'users' => [
'username' => 'password', // CHANGED
],
/*
|--------------------------------------------------------------------------
| User Repository
|--------------------------------------------------------------------------
|
| This is the user repository, which by default loads and saves all authorized
| users in a SQLite database. You can implement your own user repository
| if you want to store your users in a different store (Redis, MySQL, etc.)
|
*/
'user_repository' => \App\Server\UserRepository\DatabaseUserRepository::class,
/*
|--------------------------------------------------------------------------
| Messages
|--------------------------------------------------------------------------
|
| The default messages that the expose server will send the clients.
| These settings can also be changed at runtime in the expose admin
| interface.
|
*/
'messages' => [
'message_of_the_day' => 'Thank you for using expose.',
'invalid_auth_token' => 'Authentication failed. Please check your authentication token and try again.',
'subdomain_taken' => 'The chosen subdomain :subdomain is already taken. Please choose a different subdomain.',
],
],
];

This guide will help you to run expose as a systemd service while using nginx as webserver.

  1. Checkout Repo git clone https://github.com/beyondcode/expose /opt/expose

  2. Change Version cd /opt/expose ; git checkout tags/1.5.1 -b 1.5.1

  3. Install composer deps composer install

  4. Create Linux-User with group for systemd unit useradd -G expose expose

  5. Prepare directory for expose data mkdir /etc/expose chown -R expose:expose /etc/expose/

  6. Create and adjust /etc/expose/.expose.php

  7. Create systemd unit file (/etc/systemd/system/expose.service)

  8. Register service in systemd systemctl daemon-reload

  9. Start service systemctl start expose

  10. Start service on boot systemctl enable expose

  11. Create nginx config file /etc/nginx/sites-available/expose.vhost

  12. Activate nginx config

ln -s /etc/nginx/sites-available/expose.vhost /etc/nginx/sites-enabled/expose.vhost
systemctl reload nginx
[Unit]
Description=expose
After=network.target
Requires=network.target
[Service]
Type=simple
Restart=always
RestartSec=30
TimeoutStartSec=0
WorkingDirectory=/etc/expose
ReadWritePaths=/etc/expose
ExecStart=/usr/bin/php /opt/expose/expose serve localhost --port 3100
User=expose
Group=expose
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
server {
listen *:80;
listen [::]:80;
server_name *.my-domain.com ;
location / {
proxy_pass http://localhost:3100/;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment