-
-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working on NodeJS project - use nginx as reverse proxy / upstream Node app #240
Comments
This needs to be automated ;-) For now, have a look at vhost-gen to generate yourself a reverse proxy config. |
Thanks i think this is the answer for my question i will and will make a feed back |
I'm curious what the plan is to implement this, I notice that vhost_gen takes an r flag for this yet the nginx container never passes -r(from what I can tell), so it seems that the fix for this would be on the container level, perhaps a check for rproxy in create-vhost.sh? If I'm anywhere in the ballpark on how this might work then let me know and I'll make some time to work on it this weekend and maybe have a PR at some point. For others trying to sort this out, here's a gist with how I got it to work with my node project on port 3000. The important pieces are the IP, port, and the |
@stkrzysiak this is my current plan for setting it up:
Workflow sounds pretty simple. Once I have the API server finished and integrated into all web server it should more or less be a self-writer ;-) |
Have you thought about having it watch for changes in a proxy config file instead of a complicated API setup? i.e.: PROXY_CONF_DIR=proxy_conf/ and in there, each host to proxy would have a config file:
(or env or whatever format) That would have the 4 or 5 config settings for what ip/port to forward to. I am doing something similar to this by having a new folder for that project (in the projects folder), and then I put in a custom .devilbox/apache24.yml file which added the reverse proxy. |
Please, write step-by-step manual for use nodejs server on port in devilbox stack. my attempts weren't crowned with success |
would change to:
I'm sorry there are no step-by-step instructions. What you are asking has no easy configurable option, and is only possible with this type of advanced configuration. |
Status updateThere are two components to making this work:
The auto-start feature is currently PR-ed and will be merged soon. It will allow you to automatically have any node/npm (or others) spin up during Devilbox startup: #446 The second part will only require some documentation to copy/paste working vhost-gen configs into the project directory. So I will have to create three config templates:
|
@mrpsiho @jebog @stkrzysiak @science695 @ekam230 StatusI have successfully managed to get Node up and running behind Nginx reverse proxy: Goal:When the Devilbox starts up, the Node project should automatically start and be available via the vhosts.php intranet page by: Project info
Reverse vhost for NginxHow to customize individual vhosts: https://devilbox.readthedocs.io/en/latest/vhost-gen/customize-specific-virtual-host.html
---
vhost: |
server {
listen __PORT____DEFAULT_VHOST__;
server_name __VHOST_NAME__;
access_log "__ACCESS_LOG__" combined;
error_log "__ERROR_LOG__" warn;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# CHANGE: The port will be the only thing to adjust for projects
proxy_pass http://php:8000;
}
__REDIRECT__
__SSL__
__ALIASES__
}
# ------------------------------------------------------------------------------------------
# Do not change anything below this line
# ------------------------------------------------------------------------------------------
vhost_type:
docroot: ""
rproxy: ""
features:
ssl: |
ssl_certificate __SSL_PATH_CRT__;
ssl_certificate_key __SSL_PATH_KEY__;
ssl_protocols __SSL_PROTOCOLS__;
ssl_prefer_server_ciphers __SSL_HONOR_CIPHER_ORDER__;
ssl_ciphers __SSL_CIPHERS__;
redirect: |
return 301 https://__VHOST_NAME__:__SSL_PORT__$request_uri;
php_fpm: ""
alias: |
location ~ __ALIAS__ {
root __PATH__;
__XDOMAIN_REQ__
}
deny: |
location ~ __REGEX__ {
deny all;
}
server_status: |
location ~ __REGEX__ {
stub_status on;
access_log off;
}
xdomain_request: |
if ( $http_origin ~* (__REGEX__) ) {
add_header "Access-Control-Allow-Origin" "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Max-Age' 0;
return 200;
} Autostart script:https://devilbox.readthedocs.io/en/latest/advanced/custom-startup-commands.html
# https://github.com/Unitech/pm2
npm install pm2 -g
su -c 'cd /shared/httpd/node/node; pm2 start index.js' -l devilbox Todo:
|
I've now added Additionally reverse proxy projects are also added to integration tests via Travis CI to ensure they work on all Webservers and with all PHP images. |
UpdateReverse proxing applications feature is now finished in above mentioned PR. Currently not only NodeJS applications can easily be proxied, but also any other custom container can be attached and proxied to the webserver with valid HTTPS and even have it be displayed in the vhost section of the intranet: Examples:
Looks like this feature will now allow to extend the Devilbox with whatever programming language you wanna go with. I will post the documentation in the coming days |
DoneIts now working like a charm: GeneralNodeJS Specific |
@cytopia first of all THANK YOU for your awesome job, this env is amazing! 👏🏽 I've checked with PM2 that the node process is alive, I've What can be the issue? |
@felixmosh was this issue resolved by your PR: https://github.com/cytopia/devilbox/pull/492/files? |
Of course no :), I've changed in |
Oh, you are right! I've mapped the wrong url (I have a different config for apache). Now, I get
|
This is not a reverse proxy config, it's the normal forward config. How does your |
This is because you simply missed step 5 (the reverse proxy setup): |
I did it, the only thing I didn't done is copy all the *-reverse.yml files (cause I'm using only nginx) |
You will actually need to copy |
That is what I've done, the file suppose to be at |
Yes, did you then restart the Devilbox? |
Yeap, I've even tried to |
Are you on the latest |
Yes, I'm on latest master, I'm invoking |
WOW! 🎊
|
Hmm strange. Bind should actually autostart, no matter what. That's how it's been defined in |
FYI: @felixmosh @ekam230 @stkrzysiak @mrpsiho @jebog This has now been automated: #942 |
I noticed something intriguing, maybe it's my lack of experience. But when I use the reverse proxy for PHP to listen to my vue on port 8080 and I need to use PHP in the same environment, PHP no longer works, only vuejs. Is that right or did I configure something wrong? |
Hi! Hope you are doing well. I have a question about using devilbox while working on NodeJS project. In essence, I would like to ask how to access my Node app via custom domain like 'node-app.loc'?
I start my Node app inside a container via terminal and it is up and running on localhost:3000. But I am lost how to access it? Visiting http://node-app.loc gives me Error 403 Forbidden. I guess I could achieve what I need by modifying nginx.yml within '.devilbox' folder of my project folder, however, I don't know what exactly to put inside this config file. Please, help.
The text was updated successfully, but these errors were encountered: