diff --git a/roles/cups/tasks/nginx.yml b/roles/cups/tasks/nginx.yml new file mode 100644 index 000000000..25ee45b8c --- /dev/null +++ b/roles/cups/tasks/nginx.yml @@ -0,0 +1,16 @@ +- name: Enable http://box/print via NGINX, by installing {{ nginx_conf_dir }}/cups.conf from template + template: + src: cups.conf + dest: /etc/nginx/conf.d/cups.conf + when: cups_enabled + +- name: Disable http://box/print via NGINX, by removing {{ nginx_conf_dir }}/cups.conf + file: + path: /etc/nginx/conf.d/cups.conf + state: absent + when: not cups_enabled + +- name: Restart 'nginx' systemd service + systemd: + name: nginx + state: restarted diff --git a/roles/cups/templates/cups.conf b/roles/cups/templates/cups.conf index 8cf2b199f..1f286da4c 100644 --- a/roles/cups/templates/cups.conf +++ b/roles/cups/templates/cups.conf @@ -1,2 +1,25 @@ -ProxyPass /cups http://localhost:631 -ProxyPassReverse /cups http://localhost:631 +location ~ /print/(.*) { + proxy_pass http://127.0.0.1:631/$1; + proxy_set_header Host '127.0.0.1'; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + + sub_filter ' href="/' ' href="/print/'; + sub_filter ' action="/' ' action="/print/'; + sub_filter ' src="/' ' src="/print/'; + sub_filter_types *; + sub_filter_once off; +} + +location ~ /cups/(.*) { + proxy_pass http://127.0.0.1:631/$1; + proxy_set_header Host '127.0.0.1'; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + + sub_filter ' href="/' ' href="/cups/'; + sub_filter ' action="/' ' action="/cups/'; + sub_filter ' src="/' ' src="/cups/'; + sub_filter_types *; + sub_filter_once off; +} diff --git a/roles/cups/templates/cupsd.conf b/roles/cups/templates/cupsd.conf index 92a395cb8..254f7d4a8 100644 --- a/roles/cups/templates/cupsd.conf +++ b/roles/cups/templates/cupsd.conf @@ -1,8 +1,8 @@ ServerAlias * LogLevel warn MaxLogSize 1m -Listen {{ lan_ip }}:631 -Listen localhost:631 +#Listen {{ lan_ip }}:631 +Listen 127.0.0.1:631 Listen /var/run/cups/cups.sock Browsing On BrowseLocalProtocols dnssd