1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/SERVER.md

96 lines
3.2 KiB
Markdown
Raw Normal View History

This is mostly basic linux server configuration stuff but I felt it important to document and share the steps I took to get verdaccio running permanently on my server. You will need root (or sudo) permissions for the following.
## Running as a separate user
First create the verdaccio user:
```bash
$ sudo adduser --disabled-login --gecos 'Verdaccio NPM mirror' verdaccio
```
You create a shell as the verdaccio user using the following command:
```bash
$ sudo su verdaccio
$ cd ~
```
The 'cd ~' command send you to the home directory of the verdaccio user. Make sure you run verdaccio at least once to generate the config file. Edit it according to your needs.
2013-11-19 13:26:32 +01:00
## Listening on all addresses
If you want to listen to every external address set the listen directive in the config to:
```yaml
2013-11-19 13:26:32 +01:00
# you can specify listen address (or simply a port)
listen: 0.0.0.0:4873
```
## Run behind reverse proxy with different domain and port
If you run verdaccio behind reverse proxy, you may noticed all resource file served as relaticve path, like `http://127.0.0.1:4873/-/static`, you can resolve this by set `url_prefix`
```yaml
url_prefix: 'https://your-domain:8888'
# or
url_prefix: 'https://your-domain:8888/your-path'
```
If you do not know the protocol and host, you can define only subpath as `url_prefix`. Full URL will be constructed from the request.
```yaml
url_prefix: '/your-path'
```
> Nginx or Apache configure? Please check out Wiki ;-)
## Keeping verdaccio running forever
We can use the node package called 'forever' to keep verdaccio running all the time.
https://github.com/nodejitsu/forever
First install forever globally:
```bash
$ sudo npm install -g forever
```
Make sure you've started verdaccio at least once to generate the config file and write down the created admin user. You can then use the following command to start verdaccio:
```bash
$ forever start `which verdaccio`
```
You can check the documentation for more information on how to use forever.
## Surviving server restarts
We can use crontab and forever together to restart verdaccio after a server reboot.
When you're logged in as the verdaccio user do the following:
```bash
$ crontab -e
```
This might ask you to choose an editor. Pick your favorite and proceed.
Add the following entry to the file:
```
@reboot /usr/bin/forever start /usr/lib/node_modules/verdaccio/bin/verdaccio
```
The locations may vary depending on your server setup. If you want to know where your files are you can use the 'which' command:
```bash
$ which forever
$ which verdaccio
```
2017-05-20 19:44:41 +02:00
## Apache reverse proxy configuration
config.yaml
```yaml
url_prefix: https://npm.your.domain.com
```
Apache virtual server configuration
```apacheconfig
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName npm.your.domain.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/npm.your.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/npm.your.domain.com/privkey.pem
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
ProxyPass / http://127.0.0.1:4873/ nocanon
ProxyPassReverse / http://127.0.0.1:4873/
2017-05-20 19:44:41 +02:00
</VirtualHost>
</IfModule>
```