By xevioni
I’m attempting to follow a tutorial on how to run an NPM Server, but I’m worried that I might be getting errors either because I’m inexperienced, or because I’m running a flask WSGI server alongside it, and they could be conflicting (they are running on separate ports). Some other things to note, my server is running ipv6 and the domain explicitly requires the use of SSL. I’m using certbot as shown in the tutorials below.
Additionally, attempting to do systemctl enable default like I would expect to start the service for the server results in the following error:
Failed to enable unit: Unit file default.service does not exist.
I’m aware now that the Unit file I created in the Flask tutorial (below) is exactly what this is, but since NPM and Flask are different things (sockets, python)… I’m completely unsure of what to put in there, I don’t have the slightest clue.
I’m looking to run the flask server at root (./) and have it control stuff there, but the Hastebin server at ./hastebin.
The hastebin server is running on port 7777 currently.
I’m honestly clueless about how the nginx configuration files work, so I will need some help and direction as to what to actually put in the configuration files.
My flask server is running on user xevion at ~/testproject/ (unit myproject).
I apologize if I didn’t include any actually useful information, I tried to think up as many details as I could think of concerning my current objective and problems. Feel free to ask for any configuration files, command outputs etc. as you can if you think it’ll help me and you resolve my problems.
I followed most tutorials in here nearly word for word, so it can be expected that most names and things will be in the same location under the same or a similar name.
Hastebin GitHub Hastebin GitHub Installation How to setup a NodeJS Application for Production on Ubuntu 18.04 How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 18.04
OS Version
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Nginx Webserver Version nginx/1.14.0 (Ubuntu)
NPM Version 6.9.0
NodeJS Version v12.4.0
/etc/nginx/sites-available/default ~/haste-server/config.json
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
I’m not sure it’s exactly what you are looking for but this is what I gather from the information provided that you would need.
Setting up multiple applications behind an Nginx reverse proxy is a fairly common task. From what you’ve described, you want your Flask app to serve from the root (./) and the Hastebin app to serve from ./hastebin.
Here’s a basic example of how you might set up the Nginx configuration:
In /etc/nginx/sites-available/default:
server {
listen 80;
server_name your_domain.com; # Replace with your domain name
location / {
include uwsgi_params;
uwsgi_pass unix:/path/to/your/project/myproject.sock;
}
location /hastebin {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:7777;
}
}
In this configuration, requests to your_domain.com will be passed to your Flask application, and requests to your_domain.com/hastebin will be proxied to your Hastebin server running on port 7777.
You’ll need to replace your_domain.com with your actual domain and /path/to/your/project/myproject.sock with the path to your Flask project’s Unix socket.
Regarding the systemd unit file for your Node.js (Hastebin) app, you can create a new file at /etc/systemd/system/hastebin.service:
[Unit]
Description=Hastebin Server
After=network.target
[Service]
ExecStart=/usr/bin/node /path/to/your/hastebin/server.js
Restart=always
User=xevion
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/path/to/your/hastebin/
[Install]
WantedBy=multi-user.target
Replace /path/to/your/hastebin/ with the path to your Hastebin server. This will allow you to use systemctl start hastebin and systemctl enable hastebin to start and enable the Hastebin server at boot.
Remember to reload the systemd daemon after creating a new unit file:
- sudo systemctl daemon-reload
Also, don’t forget to restart Nginx.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.