The Automatic1111 webui for Stable Diffusion has a --share
option to
use share=True for gradio and make the UI accessible through their site
If you don’t want to expose anything externally, but do want to share it on your local network, here’s one way to do it.
Updates
–listen
On recent versions of Automatic1111 and Forge, there is the --listen
option that removes the need for a reverse proxy to expose the port. There are valid reasons why you might still want a reverse proxy, but for most people the --listen
option will be better.
The advantage of --listen
over a reverse proxy is fewer moving parts, and therefore fewer things:
- to break.
- to introduce potential security vulnerabilities.
You’ll still need to open up the appropriate port on your firewall.
I’ll leave this article up for those who might benefit from a reverse proxy.
NOTE: --listen
is a misnomer for how the behaviour changes from default. Ie it’s already listening, it’s just changing the scope of the listening.
Table of contents
Steps
Install nginx
On linux, this is simply a matter of using your package manager to install the nginx pacakge. Eg on OpenSUSE, it’s
sudo zypper install nginx
On Windows, you’ll probably have success with the Windows version.
On MacOS, brew should get you what you need.
Create the vhost
While all of the distros that I have used nginx with put the nginx configuration in /etc/nginx; each distro tends to configure the nginx directory structure a little differently. Eg on ubuntu there is sites-available
vs sites-enabled
. While on OpenSUSE it’s vhosts.d
where you’ll want to put the following config. In any case, take a look in /etc/nginx to see which is right for you.
You’ll need to stick the following configuration in which ever directory you determined above:
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:7860;
}
}
Reload nginx
sudo systemctl reload nginx
NOTE: To give users a seamless experience while site owners roll out configuration changes, nginx lets existing instances finish before killing them off. So when you make changes, you may not see the results immediately. This is a longer conversation, but for the purposes of sharing a service in your home, it probably doesn’t matter if you see an error from a broken connection. So you can speed up the process like this:
sudo systemctl stop nginx; sudo systemctl start nginx
Make sure that your firewall allows port 80
There are various solutions, that are all out of scope for this article.
But on OpenSUSE, you probably want to just do it via YaST.
Browse to the machine
Now you can browse to the machine that is running stable diffusion. In my case, this is d1
.:
Above: A screenshot of stable diffusion being accessed from another computer.
Note that we no longer need to specify :7860
in the address bar.
Considerations
Path
In the configuration above, I’ve specified
location / {
Automatic1111 breaks if you put it anywhere other than /
. Solutions exist that will probably work for Automatic1111, but I have not yet tested any. I may do a follow-up post to this if there is interest.
Port
I’ve chosen port 80 here. You could put it on anything you like, including the original 7860 by modifying these lines:
listen 80 default_server;
listen [::]:80 default_server;
I expect that Automatic1111 would work fine with TLS(HTTPS) as well, but that is also out of scope for this article.