# Anyone Services I

This guide gives an example and explains how to set up hidden services on the Anyone Network.\
\
There are several options to run **anon**. The following tabs explain how to install it as a Debian package using our APT repository or via command line tools using the NPM package.\
\
Alternatively see the page called [Install Anon in Docker](/relay/start/install-anon-on-linux/docker.md) to find Docker instructions. Or read the [Anon Client Releases](/sdk/native-sdk/releases.md) page where you'll find instructions and links to examples utilizing the Anyone Protocol [GitHub Releases](https://github.com/anyone-protocol/ator-protocol/releases).

{% tabs %}
{% tab title="NPM" %}

1. Install the `anyone-client` with `npm`, edit a custom `anonrc` and start the client with `npx`.

```bash
npm install @anyone-protocol/anyone-client
```

{% hint style="info" %}
For detailed instructions see:\
[Install NPM Package](/sdk/npm/install.md) \
[Run from CLI](broken://pages/WAoxArmmKj4oCpmDhO03)
{% endhint %}

2. Backup any existing configuration and create a custom anonrc:

```bash
mkdir -p ./anon
[ -f ./anon/anonrc ] && mv ./anon/anonrc ./anon/anonrc_$(date +"%Y%m%d_%H%M%S").bak
touch ./anon/anonrc
```

3. To be able to route traffic through anon, add some configuration to the `anonrc` file:

```bash
cat <<EOL | tee ./anon/anonrc
ORPort 0
ControlPort 0
SocksPort 127.0.0.1:9050
SocksPolicy accept 127.0.0.1
SocksPolicy reject *
DataDirectory ./anon/

HiddenServiceDir ./anon/anon_service/
HiddenServicePort 80 127.0.0.1:80
EOL
```

{% hint style="success" %}
[**HiddenServiceDir**](/sdk/native-sdk/manual.md#hiddenservicedir-directory)\
This directory will store hidden service data and keys. Ensure the specified directory has the correct permissions and is writable by anyone-client.

[**HiddenServicePort**](/sdk/native-sdk/manual.md#hiddenserviceport-virtport-target)\
This redirects traffic from the hidden service to the local nginx server on port 80.
{% endhint %}

4. Start the `anyone-client` with the custom `anonrc`:

```bash
npx anyone-client -f ./anon/anonrc
```

5. To get your service address (open a new terminal window and) check the `hostname` file located in `./anon/anon_service/`:

```bash
cat ./anon/anon_service/hostname
```

This file contains the hidden service address (your `.onion` address) for your hidden service.
{% endtab %}

{% tab title="APT " %}
Install the `anon` client as a service on Debian, edit the default `anonrc` and restart the `anon.service`.

1. Set up the Anyone Protocol apt repository and install the anon packages:

```bash
. /etc/os-release
sudo wget -qO- https://deb.en.anyone.tech/anon.asc | sudo tee /etc/apt/trusted.gpg.d/anon.asc
sudo echo "deb [signed-by=/etc/apt/trusted.gpg.d/anon.asc] https://deb.en.anyone.tech anon-live-$VERSION_CODENAME main" | sudo tee /etc/apt/sources.list.d/anon.list
```

```
sudo apt-get update --yes
sudo apt-get install anon --yes
```

{% hint style="info" %}
For detailed instructions see:\
[Install anon on Linux](/relay/start/install-anon-on-linux.md)\
[Install anon using the apt repository](/relay/start/install-anon-on-linux/apt.md)
{% endhint %}

2. Backup default configuration and create a custom `anonrc`:

```bash
[ -f /etc/anon/anonrc ] && mv /etc/anon/anonrc /etc/anon/anonrc_$(date +"%Y%m%d_%H%M%S").bak
touch /etc/anon/anonrc
```

3. To be able to route traffic through anon, add some configuration to the `anonrc` file:

```bash
sudo cat <<EOL | sudo tee /etc/anon/anonrc
ORPort 0
ControlPort 0
SocksPort 127.0.0.1:9050
SocksPolicy accept 127.0.0.1
SocksPolicy reject *
DataDirectory /var/lib/anon/

HiddenServiceDir /var/lib/anon/anon_service/
HiddenServicePort 80 127.0.0.1:80
EOL
```

4. Restart the `anon` service:

```bash
sudo systemctl restart anon.service
```

{% hint style="success" %}
[**HiddenServiceDir**](/sdk/native-sdk/manual.md#hiddenservicedir-directory)\
This directory will store hidden service data and keys. Ensure the specified directory has the correct permissions and is writable by the anon service.\
\
[**HiddenServicePort**](/sdk/native-sdk/manual.md#hiddenserviceport-virtport-target)\
This redirects traffic from the hidden service to the local nginx server on port 80.
{% endhint %}

5. To get your service address check the `hostname` file located in `./anon/anon_service/`:

```bash
sudo cat /var/lib/anon/anon_service/hostname
```

This file contains the hidden service address (your `.onion` address) for your onion service.
{% endtab %}
{% endtabs %}

## Install and Configure nginx to run a web server

In this example we'll be setting up a local web server with [Nginx](https://nginx.org) to host some content.

Install `nginx`:

```bash
 sudo apt update --yes
 sudo apt-get install nginx --yes
```

Start and Enable `nginx`:

```bash
sudo systemctl start nginx
sudo systemctl enable nginx
```

Create an `index.html` in `/var/www/html` file as a basic test:

```bash
echo "Welcome to my Anyone Anon Service" | sudo tee /var/www/html/index.html
```

Create a new nginx configuration file for your service:

```bash
sudo nano /etc/nginx/sites-available/anon_service
```

Paste the following configuration  and save to route requests to your anon service:

```
server {
    listen 127.0.0.1:80;
    server_name localhost;

    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
```

Link the configuration to the `sites-enabled` directory:

```bash
sudo ln -s /etc/nginx/sites-available/anon_service /etc/nginx/sites-enabled/
```

Reload `nginx` to apply the changes:

```bash
sudo systemctl reload nginx
```

Test the rechability of the web server locally with `curl`:

```bash
curl "http://127.0.0.1:80"
```

Test the reachability of the web server's hostname, located in `./anon/anon_service/hostname`, using `curl --socks5-hostname`:

```bash
curl --socks5-hostname 127.0.0.1:9050 "http://$(cat ./anon/anon_service/hostname)"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anyone.io/sdk/native-sdk/tutorials/services1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
