Why is nginx duplicating the folder in the path - linux

I am trying to configure Adminer with Nginx. This is my adminer.conf:
server {
listen 80;
location /adminer {
root /usr/share/webapps/adminer;
index index.php;
}
}
However, when I go to localhost/adminer I get the error /usr/share/webapps/adminer/adminer/index.php is not found (No such file or directory).
The adminer folder is duplicated and I don't know why. The location should resolve to /usr/share/webapps/adminer/index.php.

The location should just be
/ from /usr/share/webapps/adminer for localhost
/adminer from /usr/share/webapps for localhost/adminer
server {
listen 80;
location /adminer {
root /usr/share/webapps/;
index index.php;
}
}

Related

CyberPanel OpenLiteSpeed: Host Node JS Website

I bought my own VPS and installed CyberPanel. Now I want to host my application written in NodeJS (Typescript).
So I have uploaded my application into public_html folder:
The application is resulted from these commands:
"build": "tsc --project ./&&copyFiles www/* build",
"build-deploy": "npm run build && cp package*.json build && cd build && npm install --only=production",
I use the build-deploy npm run command to include the node_modules folder as well. The problem is that my website cannot be accessed. It gives a timeout error, it keeps loading the page, then a timeout error shows up.
Request Timeout This request takes too long to process, it is timed
out by the server. If it should not be timed out, please contact
administrator of this web site to increase 'Connection Timeout'.
This is my vHost Conf:
docRoot $VH_ROOT/public_html
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails xxxxxx#gmail.com
enableGzip 1
enableIpGeo 1
index {
useServer 0
indexFiles index.php, index.html
}
errorlog $VH_ROOT/logs/$VH_NAME.error_log {
useServer 0
logLevel WARN
rollingSize 10M
}
accesslog $VH_ROOT/logs/$VH_NAME.access_log {
useServer 0
logFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i""
logHeaders 5
rollingSize 10M
keepDays 10
compressArchive 1
}
scripthandler {
add lsapi:apidi5248 php
}
extprocessor apidi5248 {
type lsapi
address UDS://tmp/lshttpd/apidi5248.sock
maxConns 10
env LSAPI_CHILDREN=10
initTimeout 600
retryTimeout 0
persistConn 1
pcKeepAliveTimeout 1
respBuffer 0
autoStart 1
path /usr/local/lsws/lsphp81/bin/lsphp
extUser apidi5248
extGroup apidi5248
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}
phpIniOverride {
}
module cache {
storagePath /usr/local/lsws/cachedata/$VH_NAME
}
rewrite {
enable 1
autoLoadHtaccess 1
}
context /.well-known/acme-challenge {
location /usr/local/lsws/Example/html/.well-known/acme-challenge
allowBrowse 1
rewrite {
}
addDefaultCharset off
phpIniOverride {
}
}
vhssl {
keyFile /etc/letsencrypt/live/api.digilifesoftware.com/privkey.pem
certFile /etc/letsencrypt/live/api.digilifesoftware.com/fullchain.pem
certChain 1
sslProtocol 24
enableECDHE 1
renegProtection 1
sslSessionCache 1
enableSpdy 15
enableStapling 1
ocspRespMaxAge 86400
}
context / {
type appserver
location $VH_ROOT/public_html
startupFile server.js
binPath /usr/bin/node
appType node
maxConns 100
accessControl {
allow *
}
rewrite {
}
addDefaultCharset off
}
Please help
Check this file /usr/local/lsws/logs/stderr.log. It's node errors log, maybe you`ll find something useful)

add "www + https" to subdomain in cyberpanle + openlitespeed

I'm using the Cyberpanel for my web control panel. my web server is Open-litespeed.
https://community.cyberpanel.net/t/01-installing-cyberpanel/82
Last night I add subdomain and it's totally work fine but the question is how add "www + https" in my subdmoain ?
There is an option in crating domain and subdomains for SSL and can be activate it.
For main domain , I choese the WWW and https.
let see how my domain is open : https://www.avadminsite.io/
I add the staticcdn for my subdomain and I expect it open like this : https://www.staticcdn.avadminsite.io/
now it's working like this: https://staticcds.avadminsite.io/
The cyberpanel has vhost configuration
vhost config for domain:
docRoot $VH_ROOT/public_html
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails it is my emain section
enableGzip 1
enableIpGeo 1
index {
useServer 0
indexFiles index.php, index.html
}
errorlog $VH_ROOT/logs/$VH_NAME.error_log {
useServer 0
logLevel WARN
rollingSize 10M
}
accesslog $VH_ROOT/logs/$VH_NAME.access_log {
useServer 0
logFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i""
logHeaders 5
rollingSize 10M
keepDays 10
compressArchive 1
}
errorpage 403 {
url 403.html
}
errorpage 404 {
url 404.html
}
errorpage 500 {
url 500.html
}
scripthandler {
add lsapi:avadminsite1267 php
}
extprocessor avadminsite1267 {
type lsapi
address UDS://tmp/lshttpd/avadminsite1267.sock
maxConns 10
env LSAPI_CHILDREN=10
initTimeout 600
retryTimeout 0
persistConn 1
pcKeepAliveTimeout 1
respBuffer 0
autoStart 1
path /usr/local/lsws/lsphp80/bin/lsphp
extUser avadminsite1267
extGroup avadminsite1267
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}
phpIniOverride {
php_admin_value open_basedir "/tmp:$VH_ROOT"
}
module cache {
storagePath /usr/local/lsws/cachedata/$VH_NAME
}
rewrite {
enable 1
autoLoadHtaccess 1
}
context /.well-known/acme-challenge {
location /usr/local/lsws/Example/html/.well-known/acme-challenge
allowBrowse 1
rewrite {
}
addDefaultCharset off
phpIniOverride {
}
}
vhssl {
keyFile /etc/letsencrypt/live/icf.ir/privkey.pem
certFile /etc/letsencrypt/live/icf.ir/fullchain.pem
certChain 1
sslProtocol 24
enableECDHE 1
renegProtection 1
sslSessionCache 1
enableSpdy 15
enableStapling 1
ocspRespMaxAge 86400
}
Also the cyberpanel has vhost configuration for subdomains too
docRoot /home/avadminsite.io/staticcdn.avadminsite.io
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails myemail#mail.com
enableGzip 1
enableIpGeo 1
index {
useServer 0
indexFiles index.php, index.html
}
errorlog $VH_ROOT/logs/avadminsite.io.error_log {
useServer 0
logLevel WARN
rollingSize 10M
}
accesslog $VH_ROOT/logs/avadminsite.io.access_log {
useServer 0
logFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i""
logHeaders 5
rollingSize 10M
keepDays 10
compressArchive 1
}
phpIniOverride {
}
module cache {
storagePath /usr/local/lsws/cachedata/$VH_NAME
}
errorpage 403 {
url 403.html
}
errorpage 404 {
url 404.html
}
errorpage 500 {
url 500.html
}
scripthandler {
add lsapi:avadminsite12677235 php
}
extprocessor avadminsite12677235 {
type lsapi
address UDS://tmp/lshttpd/avadminsite12677235.sock
maxConns 10
env LSAPI_CHILDREN=10
initTimeout 60
retryTimeout 0
persistConn 1
pcKeepAliveTimeout 1
respBuffer 0
autoStart 1
path /usr/local/lsws/lsphp72/bin/lsphp
extUser icfir1267
extGroup icfir1267
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}
rewrite {
enable 1
autoLoadHtaccess 1
}
context /.well-known/acme-challenge {
location /usr/local/lsws/Example/html/.well-known/acme-challenge
allowBrowse 1
rewrite {
}
addDefaultCharset off
phpIniOverride {
}
}
Please help.
Warm Regards,
I have try to add: www.cloudlinux.wadetest.club to cyberpanel
add the A record to your DNS:
add_DNS_record
Could you navigate to cyberpanel dashboard: https://YOUR_IP:8090
Main -> Create Website
create_website
then it will works
result

Nginx reverse proxy to node.js not working

I have an angular and node app with Postgres as the db. I am deploying them to docker containers on ec2 instance. The Nginx reverse proxy on ec2 is not routing requests to node. The same setup works on my local machine. The error message I receive is: "XMLHttpRequest cannot load http://localhost:3000/api/user/login due to access control checks". Here is my docker-compose file:
version: '3.3'
networks:
network1:
services:
api-service:
image: backend
environment:
PORT: 3000
volumes:
- ./volumes/logs:/app/logs
ports:
- 3000:3000
restart: always
networks:
- network1
nginx:
image: frontend
environment:
USE_SSL: "false"
volumes:
- ./volumes/logs/nginx:/var/log/nginx/
- ./volumes/ssl/nginx:/etc/ssl/
ports:
- 80:80
- 443:443
restart: always
networks:
- network1
and my Nginx.conf is as follows:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
location / {
root /myapp/app;
try_files $uri $uri/ /index.html;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
}
location /api/ {
proxy_pass http://api-service:3000;
}
}
}
and my api url for backend is : (the commented lines are all what I have tried)
export const environment = {
production: false,
//apiUrl: 'http://api-service'
// apiUrl: '/api-service/api'
// apiUrl : 'http://' + window.location.hostname + ':3000'
//apiUrl: 'http://localhost:3000/api'
apiUrl: 'http://localhost:3000'
};
and in my angular service I am using:
const BACKEND_URL = environment.apiUrl + "/api/user/";
and in my backend app.js:
app.use("/api/user/", userRoutes);
What am I doing wrong?
Posting what worked for me in case it helps someone. Here is what worked when I moved my code to ec2 instance:
export const environment = {
production: false,
//apiUrl: 'http://localhost:3000/api'
apiUrl: '/api'
};
So, in localhost apiUrl: 'http://localhost:3000/api works but it does not work on server.

Setting up nginx with multiple IPs

I have my nginx configuration file under /etc/nginx/sites-available/ with two upstreams say
upstream test1 {
server 1.1.1.1:50;
server 1.1.1.2:50;
}
upstream test2 {
server 2.2.2.1:60;
server 2.2.2.2:60;
}
server {
location / {
proxy_pass http://test1;
}
location / {
proxy_pass http://test2;
}
}
Sending a curl request to <PrimaryIP>:80 works but I want to use <SecondaryIP1>:80 for test1 and <SecondaryIP2>:80 for test2. Is it possible to define this in nginx?
You have to have two server directives to accomplish this task:
upstream test1 {
server 1.1.1.1:50;
server 1.1.1.2:50;
}
upstream test2 {
server 2.2.2.1:60;
server 2.2.2.2:60;
}
server {
listen 80
server_name <SecondartIP1>
location / {
proxy_pass http://test1;
}
}
server {
listen 80
server_name <SecondarIP2>
location / {
proxy_pass http://test2;
}
}

Nginx redirect to external port

Have config looking something like this.
I now want the main entry to domain to be :80.
So its only nginx that can redirect to :3000 and :8081.
If the user types domain.com:3000 -> i want it to be redirected to domain.com:80.
Is that possible and still have the functionality below, whith redirection based on cookie?
map $cookie_version $mybackend {
default "127.0.0.1:3000";
"v1" "127.0.0.1:8080";
"v2" "127.0.0.1:3000";
}
...
location / {
proxy_pass http://$mybackend;
}
...
location ~ ^/(?<cver>v[12])/ {
...
add_header Set-Cookie "version=$cver;Domain=localhost;Path=/";
rewrite ^/v[12]/(.*)$ /$1 redirect;
}

Resources