Basic webserver configurations #435
-
Hello everyone, I'm currently setting up Gitea in a VM using ansible. In addition to Gitea I'm setting up Nginx as proxy to terminate ssl and handle 80 and 443 connections. The idea is to get nginx up and running ( that's done using your nginx install role ) and then configure it ( that's why I'm here ) to deploy a configuration that 1. upgrade http connections to https ( 301 rewrite ) and 2. proxy_pass' https connections to the gitea UI. Problem: I'm having HUGE problems getting a working example.. Here's my current 'testing' version: ---
- name: Install and Configure Nginx
hosts: localhost
become: true
tasks:
- name: Configure Nginx
ansible.builtin.include_role:
name: nginxinc.nginx_config
vars:
nginx_config_http_template_enable: true
nginx_config_http_template:
- template_file: http/default.conf.j2
deployment_location: /etc/nginx/conf.d/git.my.domain.conf
config:
servers:
- core:
listen: # double intended ??
- port: 80
server_name: git.my.domain
locations:
- location: /
rewrite:
code: 301
text: https://git.my.domain This causes a
I have no idea how to properly use your role.. The documentation isn't helpful sadly.. It just states examples but doesn't explain what's required to get it working. ( I had trouble even realizing that My question would be: Can you help me set this up properly? If I get good enough with the role I might be able to lend a hand with documentation and such. Thansk for reading, thanks for your great work.. The roles itself seem good, I just have starting problems :D |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
): sequence item 4: expected str instance, Undefined found. sequence item 4: expected str instance, Undefined found
failed: [localhost] (item=/etc/nginx/conf.d/git.my.domain.conf) => {
"ansible_loop_var": "item",
"changed": false,
"item": {
"config": {
"servers": [
{
"core": {
"listen": [
{
"address": "0.0.0.0",
"default_server": "true",
"port": "80"
}
],
"server_name": "git.my.domain"
},
"locations": [
{
"location": "/",
"rewrite": {
"code": "301",
"text": "https://git.my.domain"
}
}
],
"log": {
"access": false
}
}
]
},
"deployment_location": "/etc/nginx/conf.d/git.my.domain.conf",
"template_file": "http/default.conf.j2"
}, That's the result of my current tries.. I had it working once but I played around with the template and apparnetly broke smth.
|
Beta Was this translation helpful? Give feedback.
-
And we got it working thanks to @alessfg. The apparent problem was, with a correct configuration, that my jinja version was "too old" the most recent Jinja2 version with some bug fixes also fixed my deployment problem. Solution thereof: python3 -m pip install --upgrade jinja2 ! BE AWARE: Upgrading that package MIGHT break other packages you have installed that rely on older versions. Check your dependencies but upgrading should be fine for jinja2. Also my complete deployment now looks like this: ---
- hosts: git.my.domain
become: true
tasks:
- name: "Install nginx"
ansible.builtin.include_role:
name: nginxinc.nginx
vars:
nginx_enable: true
nginx_type: "opensource"
- name: "Configure nginx"
ansible.builtin.include_role:
name: nginxinc.nginx_config
vars:
nginx_config_debug_output: true
nginx_config_http_template_enable: true
nginx_config_http_template:
- template_file: http/default.conf.j2
deployment_location: /etc/nginx/conf.d/git.my.domain.conf
config:
upstreams:
- name: gitea
servers:
- address: localhost:3000
servers:
- core:
server_name: "git.my.domain"
listen:
- default_server: true
port: 80
address: 0.0.0.0
locations:
- location: /
rewrite:
return:
code: 301
text: "https://$host$request_uri"
- core:
server_name: "git.my.domain"
listen:
- default_server: true
port: 443
ssl: true
ssl:
certificate: "/etc/nginx/gitea.cer"
certificate_key: "/etc/nginx/gitea.key"
locations:
- location: /
proxy:
pass: http://gitea
set_header:
- field: Host
value: $host
- field: Connection
value: $http_connection
- field: Upgrade
value: $http_upgrade
- field: X-Real-IP
value: $remote_addr
- field: X-Forwarded-For
value: $proxy_add_x_forwarded_for
- field: X-Forwarded-Proto
value: $scheme
- name: "Install and configure Gitea"
ansible.builtin.include_role:
name: gitea Producing the following nginx configuration
|
Beta Was this translation helpful? Give feedback.
And we got it working thanks to @alessfg.
The apparent problem was, with a correct configuration, that my jinja version was "too old" the most recent Jinja2 version with some bug fixes also fixed my deployment problem.
Solution thereof:
python3 -m pip install --upgrade jinja2
! BE AWARE: Upgrading that package MIGHT break other packages you have installed that rely on older versions. Check your dependencies but upgrading should be fine for jinja2.
Also my complete deployment now looks like this: