I followed following tutorial https://jonathanmh.com/express-passport-json-web-token-jwt-authentication-beginners/ for JWT authentication. The complete code is viewable at https://gist.github.com/JonathanMH/6bd82c0954fb8f21a837ce281da4265a .
On my local machine the app runs fine but I would like to be able to deploy it on a virtual private server running Ubuntu server with NGINX.
How should my configuration for NGINX look to get it working on the server? Currently it looks like I'm running into a CORS issue or something.
After a long search I was able to find a solution for this. I had to add the cors npm package to my app.js file .
Then I had to change the 'api' calls to use the public ip adress of the server (in the jwt-vanilla.js of the tutorial) and as I'm using a server that is based in an OpenStack environment I also had to allow the port 3000 in OpenStack. (more details on installing cors can be seen in following video ( https://egghead.io/lessons/angularjs-client-setup-for-jwt-authentication )
I used following nginx config:
server {
listen 80;
server_name yourdomain.com;
location /{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3000/;
}
}
So right now I'm running nginx and on the server in the location of the app.js (port 3000) I started 'node app.js', while in the public folder I started http-server ( npm install http-server -g) which runs on 8080.
Related
can you help on the nginx configration .
my application on node express js I have two application express js i want to run in single domain.
This my server like : app.example.com
app1 run :- app.example.com/allinone/
app2 run :-app.example.com/app/
I am using the express redirect based on the root URL redirect.
res.redirect('/login')
this response redirects to the root server domain URL I want that to redirect to the location URL.
here my nginx server block code
server {
listen [::]:80;
listen 80;
server_name app.example.com;
location /allinone/ {
proxy_set_header Host $host;
proxy_redirect ~/(.*)$ /allinone/$1;
proxy_pass http://127.0.0.1:5002;
}
location /app/ {
proxy_set_header Host $host;
proxy_redirect ~/(.*)$ /app/$1;
proxy_pass http://127.0.0.1:5000;
}
}
app is working with the location host when i move to production with sub url it was not working.
I have also tried those solutions.
Express.js redirect with virtual path
proxy_set_header Host $host;
#replase with
proxy_set_header Host $http_host;
Express.js redirect with virtual path
Nginx is redirecting proxy_pass to root path automatically
Error
This page isn’t working app.example.com redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
I have tried a new clean browser but still have the same Error.
but direct open api GET endpoint /allinone/openapi not working.
Previously create-react-app ok with Nginx. Straightforward Nginx configuration was doing the job. The dev server connection goes through /sockjs-node configuration. API connection goes through /api. Everything was fine. Simulates production-like environment without hassle.
location / {
proxy_pass http://127.0.0.1:3000;
location /sockjs-node {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 7d;
}
location /api {
proxy_pass http://127.0.0.1:8080/api;
}
}
But now the latest version has a slight change. It tries to connect wss://my_local_domain:3000/ws. It skipped my proxy setup and tries directly connect to the dev server. And failed because it is cross-origin and has no SSL support.
The question is Is there a way to tell the dev server to use a path-relative URL?
I have all my website files - example.com - on my EC2 server (Ubuntu and Apache) with SSL on EC2 instance 1. I want example.com/blog to go to another EC2 instance - EC2 instance 2. How can I do that with SSL?
I'm using Ubuntu and Apache and Route 53. thanks!
One easy way to do this is with CloudFront, described in this answer at Server Fault, where you can use path patterns to determine which URLs will be handed off to which server.
Another is an Application Load Balancer (ELB/2.0), which allows the instance to be selected based on path rules.
Both of these solutions support free SSL certificates from Amazon Certificate Manager.
Or, you can use ProxyPass in the Apache config on the main example.com web server to relay all requests matching specific paths oer to a different instance.
You cannot accomplish this with Route 53 alone, because DNS does not work at the path level. This is not a limitation in Route 53, it's a fundamental part of how DNS works.
You quickly and easily achieve this by using nginx reverse proxy. Your ssl will still be managed and offloaded on the ELB level. That is listener 443 =>> 80
1) install nginx
yum install nginx
2) add to nginx config
upstream server1 {
server 127.0.0.1:8080;
}
upstream server2 {
server server2_IP_address_here:8080;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://server1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
location /blog {
proxy_pass http://server1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
I've installed GitLab on a virtual machine in Microsoft Azure in which I also have an Apache2 web server that should respond with some static websites.
Since GitLab has an embedded NGinX web server I thought that it would have been sufficient to just make these two changes:
Make apache listen to another port rather than 80 (I changed it to 8090)
Add a server block to GitLab's NGinX (firstly by adding this configuration to gitlab.rb nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;" and then by creating the following block in /etc/nginx/conf.d/serverblock.conf)
server {
root /var/www/;
server_name .notgitlabdomain.com;
access_log /etc/nginx/logs/notgitlabdomain_access.log;
error_log /etc/nginx/logs/notgitlabdomain_error.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass 127.0.0.1:8090;
add_header X-Upstream $upstream_addr;
add_header NLC_S "s";
}
}
The problem is that this is not working so far. I opened and checked whether the nginx.conf (in /var/opt/gitlab/nginx/conf/) file is actually reading the server block I added and it is. But when I follow a link in my notgitlabdomain.com domain it redirects me to notgitlabdomain.com/users/sign_in with a Sass error that couldn't import a some css files.
Open develop tools and check the request.
I guess this issue is related about the configuration of gitlab (domain url)
I am having a Amazon EC2 Ubuntu instance. I have installed LAMP server and tomcat 7. I also have application running in tomcat.
Now, my URL for apache is - http://ec2-54-xx-xx-xx.us-west-2.compute.amazonaws.com/
My URL for tomcat application is: http://ec2-54-xx-xx-xx.us-west-2.compute.amazonaws.com:8080
Instead of writing the 8080 part, I would like to call this directly via the URL http://ec2-54-xx-xx-xx.us-west-2.compute.amazonaws.com/.
I went through lot of tutorials, all are invalid, out dated or missing details. I am apache2, so the files inside the apache2 directory are below.
How can I do this "properly"? Because I will purchase a domain name in this weekend and I will replace the long amazon URL with this one soon as well.
What you need is a reverse proxy. You should setup nginx or httpd server instance, which would proxy requests from port 80 (http) to your local 8080 port (tomcat).
Here's a sample configuration for nginx:
upstream tomcat {
server 127.0.0.1:8080; # your tomcat app address
}
server {
listen 80;
root /path/to/your/app/directory;
index index.html index.htm;
server_name your.app.domain;
location / {
try_files $uri $uri/index.html $uri.html #tomcat;
}
location #tomcat {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://tomcat;
}
}