Can you use `php artisan serve` with nginx like with nodejs? - node.js

The question above is for pure education, not for use in real world.
When reading on how to deploy a nodejs app on a VPS, I have found out, that nginx is forwarding all requests to a localhost port, which is served by node a nodejs app.
here is a nodejs config in digitalocean tutorial:
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
I was wondering is the same possible with nginx and Laravel's php artisan serve? (for sure this will also need a process manager that will restart the app in case it fails.

It is possible, and somebody asked about it: How to use "php artisan serve" in a remote server - DigitalOcean. You can do a similar thing.
artisan serve is a wrapper for PHP’s built-in server, and while this is fine for pure educational reasons, “It is not intended to be a full-featured web server. It should not be used on a public network.” See Built-in web server for more.

Related

NodeJs / React wan't refresh files over https

I have a boring problem that I can't solve..
I tried in all ways but I don't understand why if I call the application through the IP:3000 it loads updated files, but if I try to call it trough https://domainname.ext it doesn't want to serve new files.
I tried to delete node_modules and rebuild it (npm install); to run "npm run eject" and rebuild the app; pm2 kill and restart; reboot the server but nothing...
The App is configured to run with Nginx as reverse proxy over https.
Classically one of the following solutions:
Browser cache ("external" Domains are cached, IPs not). Try a different Browser
Actually 2 apps running. Try to kill the process and see if it really goes down
Nginx caching?
Finally 😌
in my server block of nginx configuration i just changed from localhost to IP addr
location / {
proxy_pass http://IP.ADDR:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

reverse proxy using sails 1, nginx, and node is very version dependent, how to fix?

I would like to have a more stable deployment of a sails 1 app on an AWS ubuntu server using nginx as reverse proxy.
Goal:
To have a non-version-dependent deployment of our app.
In particular:
We have an app on an AWS server.
App details include:
mobile focused
websockets enabled
reverse proxy with nginx
app persisting with pm2
Deployment details include
AWS ubuntu 18.04 LTS
mysql 8.x database
sails 1.2.4
nginx 1.14.0
node 8.4.0
The issue:
I was only able to get the reverse proxy working with the above versions of sails, nginx, and node. Any other combination resulted in a 403 error from the app server. Postman GET requests to the server when the app is served directly return a "sails.sid" cookie. However, when the app is served through any other reverse proxy software combination, no "sails.sid" cookie comes back in the GET header. I got the same no cookie GET request with apache2 reverse proxy.
When I hit the app directly (not through the reverse proxy) the cookies returned fine.
What I have tried
different versions of node, sails1, nginx, apache2
node versions > 10.22.0 cause the error
there is a known deprecation in node > 10.22.0 of the command
link to node deprecation
The http module OutgoingMessage.prototype._headers and OutgoingMessage.prototype._headerNames properties are deprecated.
This seems to break the nginx reverse proxy handling of headers from the sails app.
I have not seen a fix in nginx, and in particular nginx version 1.16.0 will break the headers.
other things I have tried
ownership and permissions (chmod, chown) are ok
apache2 reverse proxy: same problem as with nginx 1.16.0: no headers. I.E. the reverse proxy works, but the app returns a 403 code through the apache2 reverse proxy.
various permutations of versioning: sails, nginx, node
things I might try
Somewehere in the node-modules of sails, there may lurk header code depending on this old syntax. This could possibly be patched with a replace new-for-old on the appropriate statements. Just a thought.
What I would like:
Show me how to get this app working, i.e. get all the headers back from a vanilla Postman GET request, in a way that does not depend on these specific versions of sails, nginx, and node.
If I am missing something glaringly obvious, even better.
I am using a similar setup with node 11.15.0 and it works.
What is your nginx configuration?
Here is the server block code I tried to put in the comments. Remeber that you have to symlink it to the /etc/nginx/sites-enabled folder as well. This works for straight HTTP requests. Note that your app will only see the client "127.0.0.1". If you want to get the IP addresses from your clients out in the wild, you need to get them from the nginx reverse proxy server itself.
server {
listen 80;
server_name yourDomain.com ;
location / {
proxy_pass "http://127.0.0.1:1337";
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Port $server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass_request_headers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /socket.io/ {
proxy_pass "http://127.0.0.1:1337/socket.io/";
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Port $server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass_request_headers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

How to host nodejs services into nginx server in VirtualMachine?

I wrote some nodejs services in my ubuntu local.Now I want to deploy my nodejs services into nginx server in my seperate VM.I set up the nginx in my virtual machine.How can I pull my nodejs services to nginx server and how to connect these api's through postman. I getting confusion at nginx config file.
You should setup a reverse proxy with nginx to redirect the traffic to you node application. Install node on your VM, copy your application and install all the dependencies using npm install. Afterwards, you should start the node application using node index.js where index.js is the entry point of your application. You could also use a process manager such as pm2 to start the application. Then, you have to setup the reverse proxy with nginx which is redirecting the traffic to the port of your application. (In your sample code 3000). The application should now be available on the IP of your VM. Below you find a minimal example configuration for nginx.
server {
listen 80;
server_name domain.com;
location / {
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;
proxy_cache_bypass $http_upgrade;
}
}

How To Set Up a Node.js Application for Production on Ubuntu 14.04

I have developed Rest API using Node JS, Express and MongoDb.
I have istalled MongoDB into one machine with Ubuntu Server OS and Node JS App on machine with Ubuntu Server OS.
Now i need to deploy to Production enviroments with a reverse proxy.
I have seen this post as example:
Deploy Node JS
Now my question is: the reverse proxy server using Nginx must be deploy on a separete machine? Instead Nginx is possible to use Apache?
Thanks for your help
You can deploy nginx on same machine.So your setup will be nginx listening to 80 port of the machine for incoming requests and redirecting all requests to you application as per you have specified in nginx configuration.
if you are deploying nginx on same machine and having application 8080. you can do some thing like this.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
and if you can configure apache to redirect request to your application you can replace nginx with apache.(but i have not worked with apache so as per me above configurations works.but if you want some help you can read this one link)

Access Node.js app by address on Laravel Forge server

I have my Node.js app working fine on Laravel Homestead, but now need to move it to the server. I'm using Laravel Forge for the server provisioning. The server already has Node and the required packages installed.
When running locally, I can just use Homestead's http://192.168.10.10:3000 to connect. What will the address be on my server, and how can I keep the node app running?
I can run it when I am connected via SSH, and I can see that it is outputting events received. But how do I connect the client to it? I have tried my server's IP and domain but no luck.
Once connected, how can I keep the node app running so I don't need to have an open SSH session?
Many thanks,
Sam
Install NodeJS if you don't have it already on the server:
sudo install nodejs
Push your app to whatever folder you want it.
Create an app (a site) for your NodeJS app on Laravel Forge.
At the bottom part, there will be a button to edit Nginx's configuration. If there exists a location / { part, replace it with a reverse proxy (if there isn't, just add it):
location / {
proxy_pass http://SERVER_IP:APP_PORT;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Restart nginx, run the app.
It should all be running as you want it to on the address you've provided Laravel Forge.
To set up restarting, you'll need to look into PM2. It's fairly straightforward.

Resources