|
| 1 | +# Adding support for HTTPS/SSL |
| 2 | + |
| 3 | +> All the following instructions should be adapted to your personal needs |
| 4 | + |
| 5 | +If your plan to work locally only, first generate your self-signed cert and key: |
| 6 | + |
| 7 | +```bash |
| 8 | +openssl req -x509 -nodes -newkey rsa:2048 -keyout https.key -out https.crt -subj "/CN=localhost" -days 5000 |
| 9 | +``` |
| 10 | + |
| 11 | +Then copy your cert files on build stage of your Dockerfile: |
| 12 | + |
| 13 | +```Dockerfile |
| 14 | +FROM trafex/php-nginx:latest |
| 15 | + |
| 16 | +# ... |
| 17 | + |
| 18 | +COPY https.crt /etc/nginx/ssl/default.crt |
| 19 | +COPY https.key /etc/nginx/ssl/default.key |
| 20 | + |
| 21 | +# ... |
| 22 | + |
| 23 | +``` |
| 24 | + |
| 25 | +Edit your nginx.conf file. |
| 26 | + |
| 27 | +> Check [Nginx configuration](../config/nginx.conf) for more help: |
| 28 | + |
| 29 | + |
| 30 | +```nginx |
| 31 | +server { |
| 32 | + listen [::]:443 ssl; |
| 33 | + listen 443 ssl; |
| 34 | + server_name localhost; |
| 35 | + root /var/www/html/public; |
| 36 | + |
| 37 | + ssl_certificate /etc/nginx/ssl/default.crt; |
| 38 | + ssl_certificate_key /etc/nginx/ssl/default.key; |
| 39 | + |
| 40 | + # ... the rest here |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +If you use docker-compose here is an example: |
| 45 | + |
| 46 | +```yaml |
| 47 | + php-nginx: |
| 48 | + build: ./api |
| 49 | + networks: [ backend ] |
| 50 | + ports: [ "443:443" ] |
| 51 | + working_dir: /var/www/html |
| 52 | + volumes: |
| 53 | + - ./api:/var/www/html |
| 54 | + - ./api/nginx.conf:/etc/nginx/conf.d/default.conf |
| 55 | + restart: on-failure |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | +Finally rebuild and restart your docker/compose. |
0 commit comments