Created
May 26, 2020 19:03
-
-
Save ZiTAL/a0969be015dce41dda41fce2191e8417 to your computer and use it in GitHub Desktop.
nginx: proxy to local domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/hosts | |
127.0.0.1 localhost main.zital main01.zital |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/network/local.network | |
[Network] | |
DNS=127.0.0.53 | |
Domains=main.zital main01.zital |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/nginx/sites-available/main | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
server_name main.zital; | |
root /var/www/html; | |
index index.html; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location /01/ { | |
resolver 127.0.0.53; | |
proxy_pass http://main01.zital/; | |
proxy_set_header Accept-Encoding ""; | |
sub_filter "http://main.zital/" "http://main.zital/01/"; | |
sub_filter_once off; | |
sub_filter_types *; | |
} | |
access_log /var/log/nginx/main-access.log; | |
error_log /var/log/nginx/main-error.log; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/nginx/sites-available/main01 | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name main01.zital; | |
root /var/www/html; | |
index index.html; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
access_log /var/log/nginx/main01-access.log; | |
error_log /var/log/nginx/main01-error.log; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# exec at last | |
# root required | |
systemctl daemon-reload | |
systemctl restart systemd-networkd | |
systemctl restart systemd-resolved | |
ln -s /etc/nginx/sites-available/main /etc/nginx/sites-enabled/main | |
ln -s /etc/nginx/sites-available/main01 /etc/nginx/sites-enabled/main01 | |
/etc/init.d/nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://unix.stackexchange.com/questions/442598/how-to-configure-systemd-resolved-and-systemd-networkd-to-use-local-dns-server-f
https://stackoverflow.com/questions/32542282/how-do-i-rewrite-urls-in-a-proxy-response-in-nginx