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;
}
Related
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
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;
}
}
Caddy gives me this error:
run: adapting config using caddyfile: /etc/caddy/Caddyfile:21: unrecognized directive: uri
My Caddyfile:
{
email localemail#example.com
acme_ca https://acme-v02.api.letsencrypt.org/directory
#acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
https://www.example.com {
file_server {
root /var/www/html
}
try_files {path}.html {path}
encode gzip zstd
log
}
example.com, altexample.com, www.altexample.com {
redir https://www.commerceowl.com{uri}
}
https://help.example.com {
uri /en/* strip_prefix /en
redir https://www.commerceowl.com/support{uri}
}
What's wrong with uri /en/* strip_prefix /en?
Version 2 official document (https://caddyserver.com/docs/caddyfile/directives/uri) describe like this:
uri strip_prefix /en
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;
}
}
I am using confd and etcd. I am following the confd example for nginx. I put these keys in my etcd service:
curl http://127.0.0.1:4001/v2/keys/myapp/upstream -XPUT -d dir=true
curl http://127.0.0.1:4001/v2/keys/myapp/subdomain -XPUT -d value="myapp"
curl http://127.0.0.1:4001/v2/keys/myapp/upstream/app2 -XPUT -d value="10.0.1.101:80"
curl http://127.0.0.1:4001/v2/keys/myapp/upstream/app1 -XPUT -d value="10.0.1.100:80"
It is my toml configuration:
[template]
prefix = "myapp"
keys = [
"subdomain",
"upstream",
]
owner = "nginx"
mode = "0644"
src = "nginx.tmpl"
dest = "/tmp/myapp.conf"
check_cmd = "/usr/sbin/nginx -t -c {{ .src }}"
reload_cmd = "/usr/sbin/service nginx reload"
And it is my tmpl configuration.
upstream {{.subdomain}} {
{{range $server := .upstream}}
#I want to get the key string value
server {{$sever.key}} {{$server.Value}};
{{end}}
}
server {
server_name {{.subdomain}}.example.com;
location / {
proxy_pass http://{{.subdomain}};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Here I want to catch the key string value like app2 or app1. I am only know how to get its values. I want to do something like this {{$sever.key}} but it doesn't work. The configuration above {{$sever.key}} is wrong but I did it to show what do I want.
Is this idea possible?
Is there any reserverd word for that or syntax?
I had the same problem. For me this code worked (adopted to your config):
{{range gets "/myapp/upstream/*"}}
server {{base .Key}} {{.Value}}
{{end}}
For me the main problem was the gets function. All examples I found on the net used getvs, which only provides the values. The base functions, just removes the first parts of the path of your key.
For further information, take a look at these confd docs.