# Setting up OCSP for NGINX server

## Question

How do I set up an OCSP for server-based on NGINX?

<div id="bkmrk-answer"><span>Answer</span></div>How to enable OCSP Stapling on NGINX:

1\. First check that NGINX 1.3.7 or above is installed by running the following command:

```
nginx –v
```

Versions lower than 1.3.7 do not support OCSP stapling, so you should update NGINX before proceeding with the rest of this tutorial.

2\. Check whether OCSP stapling is already enabled or not:

- Use [openssl](https://www.openssl.org/) command:

```
openssl s_client -connect login.live.com:443 -tls1 -tlsextdebug -status
```

- Scroll down to "[OCSP](https://openprovider.help/books/ssl-certificates/page/what-is-ocsp) response:"
- If OCSP is enabled, the “OCSP Stapling” is

```
OCSP Response Status: successful (0x0)
```

- If [OCSP](https://openprovider.help/books/ssl-certificates/page/what-is-ocsp) is not enabled, you won’t see any OCSP Response Data:

```
OCSP response: no response sent
```

3\. If Step 2 revealed no evidence that OCSP is enabled on your server, it is first worth checking that NGINX can actually connect to our OCSP servers. OCSP servers are at the following locations:

<div class="table-wrap" id="bkmrk-dns-hostname%28s%29-dest"><table class="confluenceTable"><tbody><tr><td class="confluenceTd">DNS HOSTNAME(S)</td><td class="confluenceTd">Destination IP</td><td class="confluenceTd">Port</td></tr><tr><td class="confluenceTd">[OCSP.ComodoCA.com](http://ocsp.comodoca.com/)  
[OCSP.usertrust.com](http://ocsp.usertrust.com/)</td><td class="confluenceTd">178.255.83.1 or 2a02:1788:2fd::b2ff:5301</td><td class="confluenceTd">Tcp/80</td></tr></tbody></table>

To check connectivity, use the following telnet command:</div>```
telnet <a class="external-link" href="http://ocsp.comodoca.com/">OCSP.ComodoCA.com</a> 80
```

If the test is successful the reply will state

```
Connected to <a class="external-link" href="http://ocsp.comodoca.com/">OCSP.ComodoCA.com</a>
```

for at least one of the ‘Destination IP’ addresses in the table above.

If the test is unsuccessful the replies will state

```
Network Unreachable
```

or / and

```
Connection Timed Out
```

Please make the required network changes to allow NGINX to connect to our OCSP servers.  
Once complete, re-run the test in Step 2 to establish whether OCSP stapling is already enabled.

4\. To enable OCSP stapling, edit the server block configuration file for your site (or nginx.conf if server blocks are not used) using the editor of your choice (example editors include nano or vim):

```
nano /etc/nginx/sites-enabled/my-domain.com-ssl.conf
```

or

```
nano /etc/nginx/nginx.conf
```

If you need to enable OCSP stapling on just one server block, it must be the “default\_server”. If you need to enable OCSP stapling on more than one server block, it must be enabled on the "default\_server" before it can be enabled on any other server block.

5\. Turn on OCSP stapling and enable the server to check OCSP by adding the following lines inside

```
the server block:<br></br>ssl_stapling on;<br></br>ssl_stapling_verify on;
```

6\. Point to a trusted certificate chain file. This must contain the intermediate &amp; root certificates in order

```
ssl_trusted_certificate /etc/nginx/ssl/full_chain.pem
```

Use the example below as a reference configuration:

```
server {<br></br>  listen 443 default_server;<br></br>  server_name <a class="external-link" href="http://mydomain.com/">mydomain.com</a><br></br><br></br>  # Change this to point to your document root.<br></br><br></br>  root /srv/www/<a class="external-link" href="http://example.com/public_html">example.com/public_html</a>;<br></br>  index index.html index.htm;<br></br><br></br>  ssl on;<br></br>  ssl_certificate /etc/nginx/ssl/<a class="external-link" href="http://mydomain.com/my_certificate.crt">mydomain.com/my_certificate.crt</a>;<br></br>  ssl_certificate_key /etc/nginx/ssl/<a class="external-link" href="http://mydomain.com/mydomain.key">mydomain.com/mydomain.key</a>;<br></br><br></br>  ssl_stapling on;<br></br>  ssl_stapling_verify on;<br></br>  ssl_trusted_certificate /etc/nginx/ssl/full_chain.pem<br></br><br></br>}
```

7\. Test your configuration is OK:

```
sudo service nginx configtest<br></br>OR<br></br>nginx -t
```

8\. Restart NGINX if OK:

```
sudo service nginx reload<br></br>OR<br></br>systemctl restart nginx
```

9\. Verify OCSP Stapling is working by repeating Step 2