How to set up the root directory for apache2 Server? - node.js

Im trying to publish my website for the first time (complete newbie in servers). Im using apache2 and the app is built with node/react/express.
The index.js file is inside myapp/packages/hotel/src.
what I did:
changed the root folder in /000-default.conf to "var/www/html/myapp/packages/hotel/src"
deleted the existing html folder with sudo rm -r html
made the git clone command sudo git clone www.xyz123.. html
When i open the website, there is "index of / " and the directories. The index of doesent even point to the src folder, its still inside the main directory.
What did i miss? It should load the index.js

Re. 1: Use an absolute path:
DocumentRoot /var/www/html/myapp/packages/hotel/src
Re. 3: Use git archive instead of clone as you don't want the .git directory to be served. If your intention was for index.js to be an app that runs on the server, then you want to use node.js instead of apache2 to serve it.

Related

How to avoid permissions problems with node and nginx directory structure?

On my production server I'm successfully using nginx to host a static site and as a reverse proxy for a node app. Currently, the node app is in /home/myUserName/apps and the site is in /var/www/siteDomain.com/html.
On my local/development machine, the html directory is inside my apps directory (../apps/html). I want to have the same directory structure in production, so that I can clone my git repository and then just run npm install in case the package.json has changed (node_modules is in .gitignore).
I get permissions problems when using git and npm in /var/www/siteDomain.com because the owner is root and siteDomain.com is drwxr-xr-x. I can clone my repo using sudo git, but then all the subdirectories (including html) are owned by root which causes problems (would have to use sudo npm, which I read can make more problems, cannot manipulate files in ftp...).
The other way I could do it is clone the repo to /home/myUserName/apps, where everything is owned by my non-root user, and then change the nginx config file to point to /home/myUserName/apps/html as the root for the static site.
What is the best way to structure my directories so that I don't have permissions problems when using git and npm? Is pointing the html root to something outside of /var/www unusual or will it problems in the future?
P.S. my local machine is Windows, I'm not very experienced with linux (which is running on production server)
You can create projects directory in /home/username/projectname
Run nginx without root permissions like described below.
Add/Change the following in your /etc/nginx/nginx.conf:
user nginx;
You should create the user and grant permissions on the webroot directories recursively.
This way only master process runs as root. Because: Only root processes can listen to ports below 1024. A webserver typically runs at port 80 and/or 443. That means it needs to be started as root.
To run master process as non root user:
Change the ownership of the following:
error_log
access_log
pid
client_body_temp_path
fastcgi_temp_path
proxy_temp_path
scgi_temp_path
uwsgi_temp_path
Change the listen directives to ports above 1024, log in as desired user and run nginx by nginx -c /path/to/nginx.conf.
And your node directory must be placed in /home/username/projectname.
Add node user, nginx user and git user to the common group and check projects permissions.

Folder structure to deploy app on EC2 instance

I am setting up a new React app on EC2 instance (ubuntu). I have installed nodeJS and npm and I am able to build my app successfully.
Issue is my code is in /var/www/html folder and my site example.com is pointed to this folder.
when I run
npm run build
It builds a folder under /html like /html/build now my app runs on example.com/build. Resources for these files comes from example.com/static/style.css etc but they actually reside under example.com/build/static
I can edit asset-manifest.json and change the path but thats not appropriate solution as I need to get rid of /build folder for production
I am not super familiar with deployments to EC2 but this looks like you just need to either copy the entire contents of your app inside var/www/html, or you need to tell apache or nginx to look to the right folder (in this case /build)
For example, with apache you probably have a file inside /etc/apache2/sites-enabled/ that is pointing to /var/www/html, you could change that to /var/www/html/build and restart apache.
You can check this for examples on how to write these configurations https://gist.github.com/rambabusaravanan/578df6d2486a32c3e7dc50a4201adca4

How to host and access files on a Netlify site

I am using Netlify to host a github repo and am trying to find a way to host additional files on the domain.
( If you don't know what Netlify is check it out. It's a fast dirty and free version of AWS code deploy as far as I understand. (Disclaimer have not used AWS code deploy))
Example
Base Domain:
https://physiome-test.netlify.com/
Load a 3D model from
https://physiome-test.netlify.com/3Dmodels/heart/fullheart.json
Does anyone know if this is possible? I understand that they only provide 'static sites' but I don't see why that couldn't include file storage so that one doesn't have to worry about CORS
Netlify will host all static content in the folder you tell it to on deploy. You are currently telling Netlify to put your whole repository into the site starting at the root of the repository. This is causing issues with your relative paths.
You can go to any path in your repository at this time on your site and get a returned response of the file.
Solution:
Build your site into one build location and have Netlify deploy that location to the site. Any path relative to the root path of the location will be the root of your site.
1. Put the body assets under your simple_heart/models directory at simple_heart/models/body
2. netlify.toml (root of your repository)
[build]
command = "cp -r ./simple_heart ./build && npm run build"
publish = "build"
3. Fix your index.html in the simple_heart to reflect the relative paths from the root of simple_heart which will now be the root of your site with the build assets physiomeportal.js and physiomeportal.min.js at the root of your site.
note: To see this, run the command from the root of your site on a local build.

Write error when trying to run unicorn: directory for pid=/var/www/twimpush/pids/unicorn.pid not writable (ArgumentError)

I've followed the steps in the DigitalOcean guides here and here towards setting up a Sinatra server using nginx and Unicorn. I'm on the second to last step:
start the Unicorn and run it as a daemon using the configuration file:
Make sure that you are inside the application directory
i.e. /my_app
unicorn -c unicorn.rb -D
Running that command, I get the error:
directory for pid=/var/www/twimpush/pids/unicorn.pid not writable
(ArgumentError)
I've tried this as both root, and as a user called deployer, to which I gave write permissions.
When I cloned my git repo, it didn't include the empty pids folder inside my repo. I added it with mkdir pids, in addition to the other required folders mentioned in the first guide, and it worked.

Deploy nodejs to OpenShift with following directory structure

OpenShift expects the following directory structure for nodejs app.
(git repo)
../-- .git
-- package.json
--server.js
--Gruntfile.js
-- ....
--/...
I have following git repository directory structure.
(git repo)
../-- .git
-- webserver ( nodejs app with package.json and gruntfile resides here)
-- mobileApp
-- dbScripts
Is it possible to direct OpenShift to consider webserver directory as nodejs app directory?
The easiest way to do this would be to move the files in the webserver directory into the root directory of the Openshift gear. That or you could alter your start and stop action hooks in .openshift/action_hooks/ to start your Nodejs application from within that webserver directory.

Resources