Add working Nginx proxy and Certbot SSL configuration
This commit is contained in:
parent
6d5d638a14
commit
97e5a78193
1 changed files with 39 additions and 3 deletions
|
|
@ -83,13 +83,49 @@
|
||||||
- cockpit
|
- cockpit
|
||||||
- nginx
|
- nginx
|
||||||
- forgejo
|
- forgejo
|
||||||
# Install System Dependencies for Nginx and Certbot
|
|
||||||
- name: Remove default Nginx site configuration
|
- name: Remove default Nginx site configuration
|
||||||
file:
|
file:
|
||||||
path: /etc/nginx/sites-enabled/default
|
path: /etc/nginx/sites-enabled/default
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Reload Nginx to apply changes
|
# --- NEW: NGINX REVERSE PROXY CONFIGURATION ---
|
||||||
|
- name: Configure Nginx reverse proxy for Forgejo
|
||||||
|
copy:
|
||||||
|
dest: "/etc/nginx/sites-available/{{ domain_name }}"
|
||||||
|
content: |
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name {{ domain_name }};
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Enable Forgejo Nginx site config symlink
|
||||||
|
file:
|
||||||
|
src: "/etc/nginx/sites-available/{{ domain_name }}"
|
||||||
|
dest: "/etc/nginx/sites-enabled/{{ domain_name }}"
|
||||||
|
state: link
|
||||||
|
|
||||||
|
- name: Reload Nginx to apply proxy routing
|
||||||
service:
|
service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: reloaded
|
state: reloaded
|
||||||
|
|
||||||
|
# --- NEW: LET'S ENCRYPT CERTIFICATE PROVISIONING ---
|
||||||
|
- name: Obtain SSL certificate from Let's Encrypt via Certbot
|
||||||
|
command: >
|
||||||
|
certbot --nginx
|
||||||
|
-d {{ domain_name }}
|
||||||
|
--email {{ letsencrypt_email }}
|
||||||
|
--agree-tos
|
||||||
|
--non-interactive
|
||||||
|
--keep-until-expiring
|
||||||
|
args:
|
||||||
|
creates: "/etc/letsencrypt/live/{{ domain_name }}/fullchain.pem"
|
||||||
Loading…
Reference in a new issue