Deploying Reactjs and PHP application together on Nginx at Ubuntu 18.04 - php

I am trying to run reactjs application and PHP application together on Nginx.
Reactjs application runs well, but I am unable to run PHP application.
I have added two server blocks for both the applications but unable to run PHP app which is actually my api/service for react js app.
Any help in this regard would be much appreciated.
Here is my nginx configuration for react js application:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/qurancom-reactjs;
index index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
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 http://localhost:3000;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
and here are my php app nginx server block configurations:
server {
listen 80;
listen [::]:80;
root /var/www/html/quran-app-services/api;
index index.php index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
try_files $uri $uri/ =404;
}
}
Thanks

Related

Serving nodejs static files in the same domain as my PHP

I have website which running on PHP, but also I have NodeJS app which is running on the same domain.
NodeJs address is /nodejs, all other requests are under PHP.
PHP project located in folder /home/php-project
PHP static files folder /home/php-project/public
NodeJS is located in - /home/nodejs-project.
NodeJS static files folder /home/nodejs-project/public
Is it possible to serve different static folders?
Here is my NodeJs code
app.use(express.static(__dirname + '/public'));
Currently all static files coming from php static folder and I can't get access to nodejs static files.
Here is the nginx config
server {
listen 80;
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
#### Comodo SSL
ssl_certificate path/to;
ssl_certificate_key path/to;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
#### Comodo SSL
ssl_certificate path/to;
ssl_certificate_key path/to;
root /home/php-project/public;
index index.php;
location / {
autoindex off;
try_files $uri $uri/ /index.php?$query_string;
}
location /node-js {
proxy_pass http://localhost:5555;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
root /home/node-js;
}
} #### End server setup
Try this:
location / {
root /home/php-project/public;
try_files $uri $uri/ /index.php?$query_string #fallback;
}
location #fallback {
root /home/nodejs-project/public;
try_files $uri $uri/ =404;
}

Wordpress stuck on "too many redirects"

I am trying to create a wordpress website that uses nginx as a reverse proxy to apache - apache serves only php requests.
I was able to successfully install wordpress but whenever I try to open the website it says "too many redirects". However when I try to open example.com/wp-admin it loads and I am able to login into and access the admin panel.
My /etc/nginx/sites-available/webproxy is:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name server_ip;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
I checked both apache and nginx error logs - empty.

Multiple relative urls and sites in Nginx

I have a server with a name of compute01.com
I have a python django application through a reverse proxy, a gitlab instance, a mediawiki php instance, and a wordpress php instance on this server.
my goal is to have the urls set up as:
compute01.com/django/
compute01.com/gitlab/
compute01.com/wiki/
compute01.com/wordpress/
so far I only have gitlab running with its own sites-enabled file
server {
listen compute01.com:80 default_server;
##listen [::]:80 default_server;
server_name compute01.com;
server_tokens off;
root /home/git/gitlab/public;
client_max_body_size 20m;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location /gitlab {
try_files $uri $uri/index.html $uri.html #gitlab;
}
location /django {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
I added the django location added to this file because its the only I way I can add that relative url to talk to the wsgi. however 404s and such get redirected to gitlab.
What I would like is four separate files in sites enabled that have the individual urls and location blocks however I am not sure what the structure would be, would it be " 4 servers" or "4 locations at a server"?

How to configure both php and nodejs app together using nginx on the same server

I have an Ubuntu VPC. I have a nodejs app running on it in some folder. I have a php app running on apache in var/www. What I want is to configure nginx so that when a user comes on mydomain.com , he/she is redirected to my node app running on port 3000 and when the user visits mydomain.com/docs , he/she is redirected to my php app running on apache on port 80.
server {
listen 80;
root /var/www;
location / {
try_files $uri $uri/ /index.html;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~/\.ht {
deny all;
}
}
My conf file for nodejs app is:
upstream app_somedomain {
server 127.0.0.1:3000;
}
server {
listen 0.0.0.0:80;
server_name mydomain.com mydomain;
root /some/path;
index index.html index.htm index.php index.js;
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://app_somedomain/;
proxy_redirect off;
}
}
I am using nginx for the first time. I am still unable to understand how to achieve this. As in how to serve my nodejs app running on port 3000 to my domain name and mydomain/docs to my php app.
Thanks.

Two sites on nginx but one getting all request

I have vps using nginx on that web server I got 2 conf (host1.com,host2.com) files on /etc/nginx/conf.d but 2 domain access to the same site. those site are on different technologies 1 PHP (Apache running on 88 ) and 1 python (gunicorn running on 5000) both site can be access from outside correctly using those ports.
site 1 conf
server{
listen 80;
root /var/www/host1.com/public;
index index.php index.html index.htm;
server_name host1.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:88;
}
location ~ /\.ht {
deny all;
}
}
host2 conf
server {
listen 80;
server_name host2.com;
access_log /var/log/nginx/fundacion.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Thanks in advance.
Restart nginx.
Clear your browser cache.

Categories