Nginx: Nuxtjs app on main domain + WordPress in a subdirectory - wordpress

I have a nuxtjs app https://damjanun.com/ running on main domain with nginx proxy setup. Now we need to install wordpress inside a sub-directory i.e: https://damjanun.com/blog . I can't get it done.

Found the solution. Here is my nginx config file for damjanun.com. The blog also works fine https://damjanun.com/blog
location /blog {
try_files $uri $uri/ /blog/index.php?q=$1;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

Related

Problem congifuring Nginx to visualize Swagger UI

I have a containerized dotnet service including swagger UI that I can locally run on localhost:7060/swagger/index.html.
I have a problem configuring nginx to point to it. Here is my weaplan.conf file that nginx detects
server {
Listen 80;
location /swagger {
root /var/www/html/weaplanservices/DataHandlerAPI;
proxy_pass http://127.0.0.1:7060;
try_files $uri $uri/ /index.html;
}
}
Note: the project exists in the exact indicated root and the containerized app works correctly
I solved this issue by reconfiguring nginx this way to serve Swagger UI:
server {
Listen 80;
location /swagger {
root /var/www/html/weaplanservices/DataHandlerAPI;
proxy_pass http://127.0.0.1:7060;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

multiple location in nginx is not working - error 404

I am trying to run two nodejs app one on default path (/) and another on /api , I have tried multiple ways but multiple locations are not working with nginx , only root domain (/) works fine, it doesn't matter which app I do assign (2nd or first). and if I try to visit (/api) it return 404 not found and (/) path is working fine.
Here is my default nginx file
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name example.com;
location /api {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ =404;
}
location / {
proxy_pass http://localhost:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ =404;
}
}
What I am doing wrong. Any help will be apricated. thanks
After Doing a lot of googling and tried many ways I have found the solution and instead of using react app as dynamic loading i generated a build of react and stored that build on a particular location and served these build files on main location with nginx.
location / {
root /home/user/gui/build;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://localhost:3002/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /static/ {
root /home/user/gui;
try_files
/gui/build$uri
=404;
}
So here (/) will try files in the root folder which is here (/home/user/gui/build) and we have index.html which is generated by react build this index.html will be served. Now the next problem was to serve react generated static files so i have created a separate location (/static/) with the same logic of / path.

Nginx returns 404 after loggin in with basic authentication

I've created a website with next.js and after deployment in my own test server , everything worked as expected.As there is and admin Area, i made a configuration to protect the /admin url using nginx basic auth.Here are my steps:
First i've installed the apache2-utils using sudo apt-get install apache2-utils on Ubuntu 18.04
I've created my credentials by running: htpasswd /etc/nginx/.htpasswd myusername .After click on enter, i've provided a password
I tried view the file content and everythinh was good because i've seen usename:hashedpassword
I made the following configuration in nginx
location /admin {
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
}
Here is my full configuration for that app.But i've hidden other configuration details(TLS,http redirect,etc..) :
server {
server_name mydomainename.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /admin {
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
try_files $uri $uri/ =404;
}
}
When i try to access the protected page,i get this :
When i tap bad credentials i don't get the request page as expected.
So when i tap the expected credentials i get a 404:
I've already read the follwing solutions:
NGINX auth_basic is giving me a '404 not found' message ...
NGINX htpasswd 404 not found
A tried other solutions as well even thaugh they aren't marked as solving the problem.
Try this ?
server {
server_name mydomainename.com;
auth_basic "Zone protege";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
auth_basic off;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /admin {
#auth_basic on;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

Configure Nginx to serve a node js app from a location within root directory

I am trying to serve a Node JS app alongside some static sites that are already functioning and only serving static content (/insta-app is one of the apps, there is another nginx file with another server block for the other ones which sit on different subdomains). I am successfuly getting the server.js app when I navigate to the URL /nodejsapp. The problem is that all the static content the app requires does not get served and comes up as a 404 (images, js files and css). I wrote a location block for nodejsapp/dist where the static content exists but this did not fix the problem. The content is being requested by a handlebars template that gets successfully called and is sitting in a views folder in the root. I am running the whole thing on an ubuntu server, and the node app is running through pm2 which is working fine when I request curl localhost:3000. How can I get the static content into the server?
Nginx server block:
server {
listen 443 ssl default_server;
root /var/www;
index index.html index.htm server.js;
server_name uat.com www.uat.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/uat.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/uat.com/privkey.pem;
location / {
try_files $uri $uri/ =404;
}
location ~ /.well-known{
allow all;
}
location /insta-app{
alias /var/www/insta-app/html;
allow all;
}
location /nodeJsApp{
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://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $proxy_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
# attempt to serve the static content of the app
location /nodeJsApp/dist{
root /var/www/sydney-sevens/dist;
try_files $uri $uri/ =404;
}
}

Nginx load balancer websocket issue

I'm new in NGINX and WebSocket systems but as per my project requirements I need to check some complex things to finish.
I'm trying to create one example using NGINX, which handles my WebSocket (Port: 1234) and HTTP Requests (Port: 80) using same Url (load balancer url).
I'm using three NGINX server, one as Load Balancer (10.0.0.163) and other two as my application server where I have installed my real APIs, 10.0.0.152 and 10.0.0.154 respectively. Right now, I have configured WebSocket on my application servers.
As per above configuration, my all requests will pass over 10.0.0.163 (load balancer) and it's proxy setting will pass the request (HTTP/WebSocket) to my application server (10.0.0.152/154).
Note : Each application server contain separate Nginx, php, websocket
Here is default (location : /etc/nginx/sites-available/) file for 10.0.0.154 server, which handles WebSocket and HTTP requests on same domain.
server{
listen 80;
charset UTF-8;
root /var/www;
index index.html index.htm index.php
server_name localhost 10.0.0.154 ;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
try_files $uri $uri/ #proxy; autoindex on;
}
location #proxy{
proxy_pass http://wb1;
}
location =/ {
proxy_pass http://wb;
proxy_http_version 1.1;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer $http_referer;
proxy_redirect off;
}
}
Following is default file (location : /etc/nginx/sites-available/) for load balancer at 10.0.0.163.
upstream wb{
server 10.0.0.154;
server 10.0.0.152;
}
server{
listen 80;
charset UTF-8;
root /var/www;
index index.html index.htm index.php
server_name 10.0.0.163 ;
location / {
try_files $uri $uri/ #proxy; autoindex on;
}
location #proxy{
proxy_pass http://wb;
}
location =/ {
proxy_pass http://wb;
proxy_http_version 1.1;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer $http_referer;
proxy_redirect off;
}
}
I found that, load balancer is working properly for HTTP requests but it's unable to proceed my WebSocket requests to my application server.
I don't know what I'm missing here .. If you guys can help me out would be great appriciate
I seen your configuration looks proper. I think you should check your load balancer & your application server configuration or versions. It maybe problem of incompatibility.

Resources