How to deploy a remove development server with Flutter Web? - nginx-reverse-proxy

I sometimes develop remotely thanks to vscode-remote and nginx reverse proxy
flutter run -d chrome --web-port=4000
I want to open flutter web dev server on other ip than http://localhost:4000
I can do that with nginx and webpack-dev-server
There is no way to open in other browser except chrome (some proxy dependencies interal from chrome)
nginx config file
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
proxy_pass http://localhost:4000;
proxy_set_header Host $host;
}
}

If you are looking for opening the flutter web app in other browser during development this is not possible as of now. Check the note here on top of this link. One option is to run flutter build web and host the build\web folder. Once hosted this can be opened in any browser like Firefox or so. But I guess you cannot debug in this mode.

Related

How to deploy Vue JS website to Ubuntu based VPS?

I have a VPS based on Linux Ubuntu.
I have two websites.
I have two domain names for both websites.
One website with domain trail-notes.tk is successfully deployed to VPS and is running on server without any ports in config file. Website is working fine. The problem is with the second website which I want to run on a specific port 4000 but on the same ip address of my server
When I did all the configurations and hit control-surface.ml it returns error "502 Bad Gateway"
How to deploy Vue applications/websites properly?
Config file of first website trail-notes.tk for nginx:
server {
listen 80;
server_name trail-notes.tk www.trail-notes.tk;
root /home/kentforth/webapps/trail-notes/dist;
index index.html index.htm;
location / {
root /home/kentforth/webapps/trail-notes/dist;
try_files $uri $uri/ /index.html;
}
error_log /var/log/nginx/vue-app-error.log;
access_log /var/log/nginx/vue-app-access.log;
}
What I already did:
Created Vue project
Created config file in vue project "vue.config.js"
Added port configuration to this file:
module.exports = {
devServer: {
port: 4000
}
};
Pushed code to github
5.Entered my VPS server
Cloned directory from github
Installed necessary dependencies:
npm install --production
Installed Vue CLI for building project
npm i #vue/cli-service
Built dist folder for production:
npm run build
in directory /etc/nginx/sites-available/ created file control-surface-frontend.conf
Added configuration to that file:
server {
listen 80;
server_name control-surface.ml www.control-surface.ml;
root /home/kentforth/webapps/vue-test/dist;
index index.html;
charset utf-8;
location / {
proxy_pass http://localhost:4000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location = /favicon.ico { access_log off; log_not_found off; }
}
Activated symlink for that file:
sudo ln -s /etc/nginx/sites-available/control-surface-frontend.conf /etc/nginx/sites-enabled/control-surface-frontend.conf
Tested symlink:
sudo nginx -t
Restarted nginx:
sudo systemctl restart nginx
15.Checked that nginx is running:
What did I do wrong?
I made wrong config file for nginx.
Here is my correct nginx config file and my website works fine:
server {
listen 80;
listen [::]:80;
server_name trail-notes.tk www.trail-notes.tk;
root /home/kentforth/webapps/trail-notes/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
error_log /var/log/nginx/vue-app-error.log;
access_log /var/log/nginx/vue-app-access.log;
}

Why am I receiving a 404 when using proxy_pass with NginX?

I'm trying to use Nginx to expose my Web APIs on port 80 using proxy_pass. The Web APIs are written in Node using Express and they are all running on separate port numbers.
I have locations working in the nginx.conf file when pulling static files from the root and /test, but receive a 404 error when trying to redirect to the API. The API I'm testing with runs on port 8080 and I'm able to access and test it using Postman.
This is using Nginx 1.16.1 being hosted on a Windows 2016 Server
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost crowdtrades.com;
//Root and /test locations are working correctly
location / {
root c:/CrowdTrades;
index index.html index.htm;
}
location /test/ {
root c:/CrowdTrades/test;
index test.html;
}
// #Test2 this is the location I'm not able to get working
location /test2/ {
proxy_set_header Host $host;
proxy_pass http://localhost:8080/api/signup/;
}
}
}
So after trying all kinds of configuration changes and restarting Nginx each time I gave up for the night. My cloud VM is scheduled to shut down at night, when I picked this up in the AM it was working. I have no idea why it's working now but restarting the server seemed to help.

How to enable linked file in nginx proxy_pass sites?

I have a server, and 2 Express-based project running on port 3000 and 4000. Landing page has default template nginx html code, with Botkit iframe embed code. Port 3000 Express server is Botkit Starter Guide project, running with no modification. Port 4000 Express server is just Hello World project. Both server executed using pm2.
Below is my /etc/nginx/sites-enabled/default config:
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
return 301 http://hwsrv-492795.hostwindsdns.com;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name hwsrv-492795.hostwindsdns.com;
location / {
try_files $uri $uri/ =404;
}
location /test01/ {
proxy_pass http://142.11.241.150:3000/;
}
location /test02/ {
proxy_pass http://142.11.241.150:4000/;
}
}
So here is what I can't solve:
Botkit Chatbot is successfully loaded on http://hwsrv-492795.hostwindsdns.com.
While Botkit Chatbot behaves normally on http://142.11.241.150:3000/, it doesn't do so on http://hwsrv-492795.hostwindsdns.com/test01/. It just load /index.html, but failed (404) to load /css/styles.css, /embed.js, and /chat.html
Hello world behaves just fine on both http://142.11.241.150:4000/ and http://hwsrv-492795.hostwindsdns.com/test02/.
I can curl those file from the server terminal, meaning that there is no problem on accessing those file. The question is, how do I enable or allow linked files and folder for sites that is generated using Express server to be readable on browser?

Unable to redirect from 80 to 8080 with nginx

I am unable to redirect my website from domain_name:8080 to domain_name:80
This is the code in my /etc/nginx/sites-available/file.
server {
listen *:80;
root /var/www/;
server_name domain_name;
location / {
proxy_pass http://127.0.0.1:8080/;
}
}
What's interesting is, I am able to access it without :8080 on LAN. I am using com.bmuschko.tomcat plugin with Gradle. Am I missing something?

Can a server run Nginx for some sites and Apache Nginx Reverse Proxy for others?

On a server ideally I'd serve my own static and WordPress sites using Cloudflare > Varnish > Nginx but since I'd also be hosting others sites for testing such as Joomla and WordPress that rely on multiple extensions that use .htaccess and such, I wouldn't be able to easily run those sites through Nginx. So I'd like to run those sites on the same server with CloudFlare > Varnish > Nginx Reverse Proxy > Apache.
The server only has 1 ip address and runs ubuntu and php-fpm and mysql. Each site would have their own separate domain name. Would this be possible?
server {
server_name example.com;
location / {
# assuming apache is on port 81 for example
proxy_pass http://127.0.0.1:81;
# to make apache detect the host header
proxy_set_header Host $host;
}
# if you have assets folders, you can let nginx serve them directly,
# instead of passing them to apache
location /images { # or /css or /js .. etc
try_files $uri =404;
}
}
Note: in the case of assets, sometimes some sites serve assets through rewrites, or even handled by the application it self, you can pass it to apache by adding that in the assets location as a fallback like this
location /images {
try_files $uri #apache;
}
location #apache {
proxy_pass http://127.0.0.1:81;
}
In apache you create a virtual host
<VirtualHost *:81>
ServerName example.com
# the rest of the config if needed
</VirtualHost>