I have spent some time trying to make Angular2 Quickstart reachable through port 80 with Browsersync working. Browsersync is the technology responsible for live refresh when your app code is modified. It creates a websocket connection with your browser on launch, detects the changes to the files located into the app directory and send the appropriate updates.
Lets say you are hosting the Angular2 Quickstart application on http://example.net/myangular2app
The base tutorial should lead you to the following situation:
We would like to use http://example.net/myangular2app and have the Browsersync stuff sending updates to the web browser (and not http://example.net:3000). And we have Nginx as the webserver.
The idea is to use proxy_pass for two streams:
/myangular2app
browser-sync
and its descendantsHere is the nginx config
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
server_name example.net;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# Here we proxy pass only the base path
location = /myangular2app/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
# Here we proxy pass all the browsersync stuff including
# all the websocket traffic
location /browser-sync {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With