Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
1
answers
864
views
Apache 2.4: Restrict access to reverse proxy by IP range, and redirect requests from all other hosts
We have a front-end proxy server that serves pages from a back-end website (both running Apache 2.4): ``` # Apache config snippet from frontend server SSLProxyEngine on ProxyPass "/blah" "https://backend.invalid/blah" ProxyPassReverse "/blah" "https://backend.invalid/blah" ``` (In other words, acces...
We have a front-end proxy server that serves pages from a back-end website (both running Apache 2.4):
# Apache config snippet from frontend server
SSLProxyEngine on
ProxyPass "/blah" "https://backend.invalid/blah "
ProxyPassReverse "/blah" "https://backend.invalid/blah "
(In other words, accessing anything under https://frontend.invalid/blah actually retrieves the content from the back-end site. This is working as expected.)
In order to do some maintenance work on the back-end site, I would now like to only allow access to the proxy (and backend site) from certain IP ranges (something like Require ip 123.123 172.20.0.0/16
(etc, for several ranges), and for all requests **not** from within these ranges, redirect those requests to a different site with a status page instead.
I suspect that this will require either some fairly complicated mod_rewrite
config (always a "several coffees required" task) and/or possibly use of the If
and Else
directives.
Can anyone advise how best (or, perhaps, how simplest) to set this up?
dave559
(451 rep)
Feb 28, 2024, 04:49 PM
• Last activity: Apr 26, 2025, 03:43 PM
0
votes
0
answers
26
views
Apache: rewrite URI path to (canonical) mixed case version and load actual content via an Alias?
We need to do some URI mangling for some web content that (for historical reasons) has been promoted using mixed case URIs. The address is `www.domain.invalid/ACRONYM/pROJECT` (with various pages contained within that folder). `/ACRONYM/pROJECT` is actually ultimately served from a UserDir: `AliasMa...
We need to do some URI mangling for some web content that (for historical reasons) has been promoted using mixed case URIs.
The address is
www.domain.invalid/ACRONYM/pROJECT
(with various pages contained within that folder).
/ACRONYM/pROJECT
is actually ultimately served from a UserDir:
AliasMatch "(?i)^/ACRONYM/pROJECT(.*)" "/home/someuser/htdocs/pROJECT$1"
What I want to do is convert requests for lower (well, any - hence NC (NoCase) flag) case requests to the "canonical" mixed case form (so that this is what is presented to site visitors), and then load the content from the UserDir via the Alias:
RewriteRule "^/acronym/project(.*)$" "/ACRONYM/pROJECT$1" [NC]
…with the AliasMatch
rule (referred to above) following this in my server config (am I right in thinking that both Redirect and also Rewrite are applied before any Alias?). I am also not sure whether I might need a RewriteCond
of some sort here?
I have **[LogLevel alert rewrite:trace2](https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging)** temporarily enabled on my test server, and it **seems** that mod_rewrite
is indeed converting the request to the desired URI case, but Apache then seems to be trying to look in the filesystem under the DocumentRoot, rather than having followed the Alias? (Other, simpler, Alias'es on the server, without this cumbersome two-stage process, do work OK.)
Example log output:
rewrite '/acronym/project/somepage' -> '/ACRONYM/pROJECT/somepage'
setting lastsub to rule with output /ACRONYM/pROJECT$1
local path result: /ACRONYM/pROJECT/somepage
prefixed with document_root to /var/www/html/ACRONYM/pROJECT/somepage
go-ahead with /var/www/html/ACRONYM/pROJECT/somepage [OK]
dave559
(451 rep)
Apr 11, 2025, 04:16 PM
0
votes
1
answers
37
views
Apache: How do I redirect all userdir user web spaces to a different server?
We want to move our user web spaces (eg, `www.domain.invalid/~usersite`) to a different server (`webhomes.domain.invalid/~usersite`), but we want to ensure that existing incoming links and bookmarks get redirected to the new server. My attempts at trying to get the right syntax/regexp for an Apache...
We want to move our user web spaces (eg,
www.domain.invalid/~usersite
) to a different server (webhomes.domain.invalid/~usersite
), but we want to ensure that existing incoming links and bookmarks get redirected to the new server.
My attempts at trying to get the right syntax/regexp for an Apache Redirect
or RewriteRule
haven't yet been successful.
I essentially want to match on ^/~
followed by anything (?) and redirect it as a request to the corresponding location on the new server, including the ~username
part and the rest of the request URI , where it exists.
We are currently using Apache 2.4.
dave559
(451 rep)
Apr 4, 2025, 11:12 AM
• Last activity: Apr 4, 2025, 01:25 PM
0
votes
0
answers
49
views
Help needed with .htaccess
I have a website which needs to be changed from Nginx to Apache webserver. The index directory is `nl.html` but the HTML extension is removed from the address bar. If I visit the website `example.com` it shows in the address bar the following URL: `example.com/nl` but actually it's `nl.html`. At the...
I have a website which needs to be changed from Nginx to Apache webserver.
The index directory is
nl.html
but the HTML extension is removed from the address bar.
If I visit the website example.com
it shows in the address bar the following URL: example.com/nl
but actually it's nl.html
.
At the moment I have the following .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
When I visit the website the root URL is shown without the /nl
.
If I visit /nl/blog
it shows a 404 but it should show /nl/blog.html
the issue also appears on other files.
What am I missing here?
Noob
(161 rep)
Jun 25, 2024, 08:07 PM
• Last activity: Jun 25, 2024, 08:52 PM
0
votes
0
answers
774
views
configure redirect rules in a apache reverse proxy
I have a apache reverse proxy setting where I have to redirect all requests from abc.com to abc-test.com, the backend for this proxy is a AWS ALB. I have the below config which is not working: ```ServerName abc.com ProxyRequests Off ProxyPass / https://internal-us-east-1.elb.amazonaws.com/ retry=0 c...
I have a apache reverse proxy setting where I have to redirect all requests from abc.com to abc-test.com, the backend for this proxy is a AWS ALB. I have the below config which is not working:
abc.com
ProxyRequests Off
ProxyPass / https://internal-us-east-1.elb.amazonaws.com/ retry=0 connectiontimeout=300 timeout=300
ProxyPassReverse / https://internal-us-east-1.elb.amazonaws.com
SSLProxyEngine on
SSLProxyVerify none
Order allow,deny
Allow from all
ProxyPreserveHost On
RewriteEngine On
RewriteRule ^(.*)$ https://abc-test$1 [L,R]
I have multiple other virtual hosts in the same apache config with different backends, surprisingly the above vhost is being redirected to a different backend. Only having a redirect rule in vhost replicates this behavior else things are fine.
Any help on this would be appreciated.
Karthik K
(421 rep)
Aug 4, 2021, 03:05 PM
• Last activity: Aug 4, 2021, 03:08 PM
0
votes
1
answers
210
views
Path rewriting/aliasing upon SSH connection
I've migrated my git repositories from Gitlab to Gogs and I've taken the opportunity to change some organization/group names and reorganize repositories. I'd like to maintain the current Git+SSH URLs working however for projects using composer or other packagers. I've looked for a way to do it insid...
I've migrated my git repositories from Gitlab to Gogs and I've taken the opportunity to change some organization/group names and reorganize repositories.
I'd like to maintain the current Git+SSH URLs working however for projects using composer or other packagers.
I've looked for a way to do it inside Gogs but nothing seems to exist to this purpose so I had another idea (which could also be useful in other contexts): rewriting the SSH path on the server, like Apache does with mod_rewrite. Is there a way to do just that with SSH? Note that adding a command in the
.authorized_keys
is a bit tricky since Gogs already uses it to mediate access to the repositories through a command.
lgeorget
(14352 rep)
Mar 22, 2021, 08:32 AM
• Last activity: Mar 27, 2021, 06:05 PM
0
votes
1
answers
681
views
HTTPD Redirect Rule as Proxy is giving me file not found error. How do I proxy to an external url?
I have a reverse proxy to AWS Elasticsearch. I am having issues with using `RedirectRule`: no matter what I try, my URL is being interpreted as a file. SSLProxyEngine On ProxyRequests On ProxyPreserveHost On RewriteEngine On RewriteRule /test-api https://vpc-cls-elasticsearch-test-tmqu2s2mcftvsuqe.a...
I have a reverse proxy to AWS Elasticsearch. I am having issues with using
RedirectRule
: no matter what I try, my URL is being interpreted as a file.
SSLProxyEngine On
ProxyRequests On
ProxyPreserveHost On
RewriteEngine On
RewriteRule /test-api https://vpc-cls-elasticsearch-test-tmqu2s2mcftvsuqe.amazonaws.com [P]
ProxyPassReverse /test-api https://vpc-cls-elasticsearch-test-tmqu2s2mcftvsuqe.amazonaws.com
Calling https://example.com/test-api always returns this error:
The requested URL /cls-api was not found on this server
How can I get this to work without the existence of an actual file on my server?
gerbdla
(11 rep)
Mar 16, 2021, 03:59 PM
• Last activity: Mar 17, 2021, 06:21 PM
1
votes
2
answers
475
views
URL rewriting for root of website
This is the configuration of my Apache 2.4.37 webserver on Centos 8. File `/etc/httpd/conf.d/mysite.conf`: ServerName mysite.com DocumentRoot "/var/www/html" RewriteEngine on RewriteCond %{SERVER_NAME} =mysite.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] File `/etc/htt...
This is the configuration of my Apache 2.4.37 webserver on Centos 8.
File
/etc/httpd/conf.d/mysite.conf
:
ServerName mysite.com
DocumentRoot "/var/www/html"
RewriteEngine on
RewriteCond %{SERVER_NAME} =mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
File /etc/httpd/conf.d/mysite-ssl.conf
:
ServerName mysite.com
DocumentRoot "/var/www/html"
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
ErrorDocument 403 /error403.html
ErrorDocument 404 /error404.html
ErrorDocument 405 /error405.html
ErrorDocument 500 /error500.html
RewriteEngine on
# First rule block
RewriteRule ^/$ /index.php [R,L]
# Second rule block
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
TraceEnable off
The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php
to https://mysite.com/anypage/
, hiding PHP file extensions and making permalinks nicer to see.
I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/
returned a File not Found. Now it works.
However, a minor annoyance is that https://mysite.com/
redirects to https://mysite.com/index/
(since it loads the file index.php
).
My question: How can this configuration be changed so that the URL https://mysite.com/
stays the same?
dr_
(32068 rep)
Nov 20, 2020, 04:48 PM
• Last activity: Nov 25, 2020, 12:17 PM
3
votes
1
answers
1204
views
Rewrite rule doesn't work in NGINX
Consider a URL as shown below: http://myDomain.tld/anAddress/myFile.pdf?X=zzz&Y=kkk How can I have it as : http://myDomain.tld/anAddress/myFile.pdf/zzz/kkk I want to get rid of both `?X` and `&Y`. I'd be glad if someone let me know what rule I should use. **MY SERVER BLOCK :** server { listen 80; se...
Consider a URL as shown below:
http://myDomain.tld/anAddress/myFile.pdf?X=zzz&Y=kkk
How can I have it as :
http://myDomain.tld/anAddress/myFile.pdf/zzz/kkk
I want to get rid of both
?X
and &Y
. I'd be glad if someone let me know what rule I should use.
**MY SERVER BLOCK :**
server {
listen 80;
server_name _;
location / {
root /my/root/path;
rewrite ^/(.*)pdf/(.*)/(.*)$ /$1?md5=$2&expires=$3 break;
secure_link $arg_md5,$arg_expires;
autoindex on;
secure_link_md5 "$secure_link_expires$uri aWord";
if ($secure_link = "") { return 403; }
if ($secure_link = "0") { return 410; }
}
}
---------------------------------------------------------------------------
**Purpose :** To be more precise, my URL is like:
http://myDomain.tld/anAddress/myFile.pdf?md5=So1Me2Ha3Sh4&expires=123456789
I want it to be like:
http://myDomain.tld/anAddress/myFile.pdf/So1Me2Ha3Sh4/123456789
In **Apache**, we can use:
RewriteRule ^(.*)pdf/(.*)/(.*)$ $1?md5=$2&expires=$3
When I tried to convert it to NGINX form, it became:
rewrite ^/(.*)pdf/(.*)/(.*)$ /$1?md5=$2&expires=$3 break;
But it didn't work.
Parsa Samet
(777 rep)
Jan 8, 2017, 01:34 PM
• Last activity: Sep 19, 2020, 03:28 PM
0
votes
1
answers
577
views
Apache RewriteCond not matching on `REQUEST_FILENAME` even though file exists?
Trace log: ``` apache_1 | [Wed Nov 20 17:14:43.950796 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] init rewrite engine with requested uri /css/main.css apache_1 | [Wed Nov 20 17:...
Trace log:
apache_1 | [Wed Nov 20 17:14:43.950796 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] init rewrite engine with requested uri /css/main.css
apache_1 | [Wed Nov 20 17:14:43.950822 2019] [rewrite:trace3] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] applying pattern '^' to uri '/css/main.css'
apache_1 | [Wed Nov 20 17:14:43.950836 2019] [rewrite:trace4] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] RewriteCond: input='/css/main.css' pattern='-f' => not-matched
apache_1 | [Wed Nov 20 17:14:43.950839 2019] [rewrite:trace3] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] applying pattern '^' to uri '/css/main.css'
apache_1 | [Wed Nov 20 17:14:43.950842 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] rewrite '/css/main.css' -> '/index.php'
apache_1 | [Wed Nov 20 17:14:43.950845 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] local path result: /index.php
apache_1 | [Wed Nov 20 17:14:43.950850 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] prefixed with document_root to /var/www/html/public/index.php
apache_1 | [Wed Nov 20 17:14:43.950852 2019] [rewrite:trace1] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] go-ahead with /var/www/html/public/index.php [OK]
Important bit is:
RewriteCond: input='/css/main.css' pattern='-f' => not-matched
Why is this not finding the file? It is definitely there.
The config has:
DocumentRoot /var/www/html/public/
And the file is located at: /var/www/html/public/css/main.css
.
---
Running strace
on apache I see the following:
apache_1 | [pid 11] poll([{fd=9, events=POLLIN}], 1, 3000
apache_1 | [pid 10] ) = 0 (Timeout)
apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0
apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112492
apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0
apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112592
apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0
apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112692
apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0}
apache_1 | [pid 67] [{EPOLLIN, {u32=3893182512, u64=140578172780592}}], 52, -1) = 1
apache_1 | [pid 59] [{EPOLLIN, {u32=3893182512, u64=140578172780592}}], 52, -1) = 1
apache_1 | [pid 67] accept4(3,
apache_1 | [pid 59] accept4(3,
apache_1 | [pid 67] {sa_family=AF_INET, sin_port=htons(42176), sin_addr=inet_addr("172.18.0.1")}, [128->16], SOCK_CLOEXEC) = 16
apache_1 | [pid 59] 0x7fda85ffad30, , SOCK_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
apache_1 | [pid 67] futex(0x7fdae80d3160, FUTEX_WAKE_PRIVATE, 1) = 1
apache_1 | [pid 59] epoll_wait(13,
apache_1 | [pid 67] epoll_wait(13,
apache_1 | [pid 22] ) = 0
apache_1 | [pid 22] futex(0x7fdae80d30e8, FUTEX_WAKE_PRIVATE, 1) = 0
apache_1 | [pid 22] getsockname(16, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("172.18.0.3")}, [128->16]) = 0
apache_1 | [pid 22] fcntl(16, F_GETFL) = 0x2 (flags O_RDWR)
php-main_1 | - - 20/Nov/2019:17:40:08 +0000 "GET /css/main.css" 200
apache_1 | [pid 22] fcntl(16, F_SETFL, O_RDWR|O_NONBLOCK) = 0
apache_1 | [pid 22] read(16, "GET /css/main.css HTTP/1.1\r\nHost"..., 8000) = 90
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966703 2019"..., 249[Wed Nov 20 17:40:08.966703 2019] [rewrite:trace2] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] init rewrite engine with requested uri /css/main.css
apache_1 | ) = 249
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966779 2019"..., 240[Wed Nov 20 17:40:08.966779 2019] [rewrite:trace3] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] applying pattern '^' to uri '/css/main.css'
apache_1 | ) = 240
apache_1 | [pid 22] stat("/css/main.css", 0x7fdae534f8d0) = -1 ENOENT (No such file or directory)
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966875 2019"..., 259[Wed Nov 20 17:40:08.966875 2019] [rewrite:trace4] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] RewriteCond: input='/css/main.css' pattern='-f' => not-matched
apache_1 | ) = 259
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966925 2019"..., 240[Wed Nov 20 17:40:08.966925 2019] [rewrite:trace3] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] applying pattern '^' to uri '/css/main.css'
apache_1 | ) = 240
apache_1 | [pid 22] getpid() = 13
apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966980 2019"..., 236[Wed Nov 20 17:40:08.966980 2019] [rewrite:trace2] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] rewrite '/css/main.css' -> '/index.php'
---
**Edit**
Why is Apache trying to read /css/main.css
?? Why is it not using the document root in there
Chris Stryczynski
(6603 rep)
Nov 20, 2019, 05:17 PM
• Last activity: Nov 20, 2019, 06:11 PM
2
votes
1
answers
4543
views
Rewrite source IP in TCP replies using iptables
I'd like to rewrite the source IP on TCP/514 traffic leaving a redhat machine, for connections that weren't initiated from the machine. The machine receives TCP/514 traffic on an interface, for example 10.10.0.20, and then I'd like to return the traffic as though the reply is from 10.10.0.15 (which...
I'd like to rewrite the source IP on TCP/514 traffic leaving a redhat machine, for connections that weren't initiated from the machine.
The machine receives TCP/514 traffic on an interface, for example 10.10.0.20, and then I'd like to return the traffic as though the reply is from 10.10.0.15 (which isn't assigned to the machine).
If I was initiating the connection, then I could use the nat table, and:
iptables -A POSTROUTING -t nat -p tcp --sport 514 -j SNAT --to=10.10.0.15
..but since I'm replying to incoming traffic, I can't make it hit the nat table (as far as I can tell). Ignoring the reasons *why* I need to do things this way, how can I make this work?
More background:
> It's a redhat 7 machine sitting behind a Netscaler VIP which receives
> syslog traffic over TCP (not UDP). I'm using client IP passthrough on
> the VIP. Due to the firewall seeing return traffic coming from the
> syslog server IP, not the VIP's IP, the firewall is dropping the
> traffic, and hence I'd like to rewrite TCP replies from the syslog
> server so they come from the VIP's IP address. Since the traffic
> doesn't originate from the backend server, I don't seem to be able to
> use the nat table (and therefore no -j SNAT
).
What I see now is:
13:13:45.439683 IP 10.10.0.8.31854 > 10.10.0.20.514: Flags [S], seq 544116376, win 8190, options [mss 1460], length 0
13:13:45.439743 IP 10.10.0.20.514 > 10.10.0.8.31854: Flags [S.], seq 4163333198, ack 544116377, win 14600, options [mss 1460], length 0
What I want to see is:
13:13:45.439683 IP 10.10.0.8.31854 > 10.10.0.20.514: Flags [S], seq 544116376, win 8190, options [mss 1460], length 0
13:13:45.439743 IP 10.10.0.15.514 > 10.10.0.8.31854: Flags [S.], seq 4163333198, ack 544116377, win 14600, options [mss 1460], length 0
Daneel
(928 rep)
Aug 19, 2015, 06:47 AM
• Last activity: Sep 23, 2019, 09:16 AM
0
votes
1
answers
714
views
Apache RewriteMap with wildcard
We want to migrate multiple domains on new servers. In the first step (though from a SEO point of this is not recommendable) everything has to be redirected to the new domain's root. Later the team wants to have more fine grained redirects (thus the usage for RewriteMaps) I thought of using somethin...
We want to migrate multiple domains on new servers. In the first step (though from a SEO point of this is not recommendable) everything has to be redirected to the new domain's root.
Later the team wants to have more fine grained redirects (thus the usage for RewriteMaps)
I thought of using something like this:
^/(.*) https://www.newdomain.com/
But it seems I am on the wrong track
Sascha
(245 rep)
Jun 7, 2019, 10:16 AM
• Last activity: Jun 7, 2019, 11:06 AM
2
votes
3
answers
7924
views
Nginx redirect/rewrite a domain.a to domain.b/foo/ without changing a url
I have a problem with the implementation of such redirect: https://domain.a/ => https://domain.b/foo/ without changing a url to domain.b. I would like to see the contents of the URL domain.a from domain.b/foo/ in browser address bar.
I have a problem with the implementation of such redirect:
https://domain.a/ => https://domain.b/foo/
without changing a url to domain.b. I would like to see the contents of the URL domain.a from domain.b/foo/ in browser address bar.
gruntboy
(416 rep)
Jan 4, 2017, 10:13 AM
• Last activity: Feb 2, 2019, 12:28 PM
4
votes
3
answers
27594
views
Deny access to subfolder and file with .htaccess
I need to deny access to configuration files under some subfolder. Currently I have this rule but it doesn't work: Order deny,allow Deny from all If I go to `www.mysite.com/foo/foo2/file.xml`, I can view the file. I need to deny all file accesses into `foo`and `bar` recursively **UPDATE** I have tri...
I need to deny access to configuration files under some subfolder. Currently I have this rule but it doesn't work:
Order deny,allow
Deny from all
If I go to
www.mysite.com/foo/foo2/file.xml
, I can view the file. I need to deny all file accesses into foo
and bar
recursively
**UPDATE**
I have tried this this configuration but have an Internal Error
Order Allow,Deny
Deny from all
stecog
(2341 rep)
Aug 6, 2015, 01:49 PM
• Last activity: Aug 20, 2018, 07:33 AM
1
votes
1
answers
251
views
Redirect all example.com/paths that don't start with example.com/wiki to example.com/wiki - NginX Proxy
I recently moved my site from Wordpress to confluence, and I'm having trouble with page redirects. Ive setup a custom 404 page for my Confluence, but it only works if you type https://www.freesoftwareservers.com/asdasdas But if you go to an old link, like https://www.freesoftwareservers.com/index.ph...
I recently moved my site from Wordpress to confluence, and I'm having trouble with page redirects. Ive setup a custom 404 page for my Confluence, but it only works if you type
https://www.freesoftwareservers.com/asdasdas
But if you go to an old link, like
https://www.freesoftwareservers.com/index.php/2015/09/03/install-dd-wrt-on-linksys-ea6500/
It takes you to my "confluence" page, but the
/wiki
is a special plugin that I want to be the public facing side. I access the page via a different subdomain then www.
My "workaround" would be one of two things,
1) Redirect all https://www.freesoftwareservers.com/index.php/*
to https://www.freesoftwareservers.com/wiki
2) Redirect all https://www.freesoftwareservers.com/(Anything BUT /wiki)
to https://www.freesoftwareservers.com/wiki
I found something close on NginX site, but it was more complicated that what I need and I was having trouble with the expression needed.
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
Here’s a sample NGINX rewrite rule that uses the rewrite directive. It matches URLs that begin with the string /download and then include the /media/ or /audio/ directory somewhere later in the path. It replaces those elements with /mp3/ and adds the appropriate file extension, .mp3 or .ra. The $1 and $2 variables capture the path elements that aren’t changing. As an example, /download/cdn-west/media/file1 becomes /download/cdn-west/mp3/file1.mp3.
server {
...
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
return 403;
...
}
Perhaps I need to split this into 2 parts, a server block that returns 404 and a 404 handler, but I'd like to keep this all in my existing nginx server block.
BTW I am already using the following rewrite rule to redirect domain.com/ to domain.com/wiki, but that only works if you type https://www.freesoftwareservers.com without anything at the end.
rewrite ^/$ /wiki permanent;
Any help is appreciated, there are many broken links to my site floating around the interweb :)
FreeSoftwareServers
(2682 rep)
Oct 10, 2016, 02:52 AM
• Last activity: Jul 4, 2018, 07:17 AM
0
votes
2
answers
884
views
An optimal way of nginx rewrite rule building for pretty URL
The webpages are accecced in the following manner: example.com/?site=website In this example, I'm accessing the website located on `example.com domain`. Could anyone suggest an optimal way of rewriting rules, so the above would be shown and accessed by `example.com/website`? nginx, Centos 7
The webpages are accecced in the following manner:
example.com/?site=website
In this example, I'm accessing the website located on
example.com domain
.
Could anyone suggest an optimal way of rewriting rules, so the above would be shown and accessed by example.com/website
?
nginx, Centos 7
Tarlan Mammadzada
(245 rep)
Aug 2, 2017, 03:49 PM
• Last activity: Feb 3, 2018, 07:17 PM
-1
votes
1
answers
7603
views
NGINX rewrite rules not working
I am playing with NGINX rewrite rules, but no matter what I do, things wont work. The current link: - `/tutorials/index.php?article=2` How I want it - `/tutorials/2` My - current - NGINX rewrite conf/rule: location / { try_files $uri $uri/ =404 /index.php?$args; rewrite ^/tutorials/([0-9]+)$ /tutori...
I am playing with NGINX rewrite rules, but no matter what I do, things wont work.
The current link:
-
/tutorials/index.php?article=2
How I want it
- /tutorials/2
My - current - NGINX rewrite conf/rule:
location / {
try_files $uri $uri/ =404 /index.php?$args;
rewrite ^/tutorials/([0-9]+)$ /tutorials/index.php?article=$1 last;
}
What am I doing wrong here?
---
My NGINX configuration file:
server {
# Hide php extension: ".php"
if (!-e $request_filename) {
rewrite ^(.*)$ /$1.php;
}
# Redirect to HTTPS
if ($scheme = http) { return 301 https://$host$request_uri ; }
# Access rule(s)
location / {
try_files $uri $uri/ =404 /index.php?$args;
}
location ~ ^/tutorials/([[:digit:]]+)$ {
rewrite ^ /tutorials/index.php?article=$1 last;
}
# Enable: PHP FPM
location ~ \.php$ {
if ($request_uri ~ /tutorials/index\.php) {
return 302 $scheme://$host/tutorials/$arg_article;
}
# Allow user execution of PHP
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-alpha.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
client_max_body_size 5M;
}
}
blade19899
(577 rep)
Aug 27, 2017, 05:54 PM
• Last activity: Aug 29, 2017, 08:06 AM
1
votes
0
answers
251
views
Correct configuration of nginx for rewrite and access control
Here is my current nginx config server_name web.com; server_tokens off; root /usr/share/nginx/html/web; index index.php; if ( $request_uri ~ "/index.(php|html?)" ) { rewrite ^ /$1 permanent; } location / { try_files $uri $uri/ /index.php?$args =404; } error_page 404 /404.html; error_page 500 502 503...
Here is my current nginx config
server_name web.com;
server_tokens off;
root /usr/share/nginx/html/web;
index index.php;
if ( $request_uri ~ "/index.(php|html?)" ) {
rewrite ^ /$1 permanent;
}
location / {
try_files $uri $uri/ /index.php?$args =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
What I'm trying to do:
1.
web.com?page=somepage&other_arg=arg&..
rewrite to web.com/somepage/arg/...
.
My methods didn't work, sometimes giving errors: failed (104: Connection reset by peer) while reading response header from upstream
or accept4() failed (24: Too many open files)
2. Allow direct access via browser URL only to index.php in root folder. Other files and directories can't be accessed via browser (but can through GET,POST, etc)
I used internal
directive, worked as expected, however I couldn't set exception for index.php
Could anyone suggest an optimal method of doing that?
Sonya Seyrios
(13 rep)
Aug 5, 2017, 04:08 PM
• Last activity: Aug 5, 2017, 04:40 PM
0
votes
1
answers
794
views
Rewrite rule nginx, token
I have a java application which is behind nginx proxy pass. When the URL is called the application automatically creates a path for the served content. So when you call `https://somedomain.com` you get `https://somedomain.com/todayisaniceday` This is the the proxy pass directive and the rewrite rule...
I have a java application which is behind nginx proxy pass.
When the URL is called the application automatically creates a path for the served content.
So when you call
https://somedomain.com
you get https://somedomain.com/todayisaniceday
This is the the proxy pass directive and the rewrite rule in my nginx:
location /URI{
proxy_pass http://IP:PORT/URI ;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
}
location ~ ^/([a-zA-Z0-9=\?]+)$ {
rewrite ^/(.*)$ / break;
}
I'm implementing one token authentication mechanism.
What I would like to achieve is the following:
when you call:
https://somedomain.com/something?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
The URL will stay and will be not rewritten by the java application.
So basically when there is this string ?jwt=
in the url it should keep it and everything behind it.
I was trying something like this:
rewrite ^/(.*)$ /?jwt=$1 break;
but without success.
Any ideas ?
Thanks for the help.
DaWe4444
(123 rep)
Jun 6, 2017, 02:02 PM
• Last activity: Jun 6, 2017, 02:30 PM
1
votes
1
answers
855
views
Replace single quotes for strings divided by blank space from variable
I'm writing a bash script where I'm reading in a variable via `read` this two strings: log.*.console.log log.*.log They are separated by space. How can I rewrite the strings that the output from the variable for the next program called in the script will have them in this form ? `'log.*.console.log'...
I'm writing a bash script where I'm reading in a variable via
read
this two strings:
log.*.console.log log.*.log
They are separated by space.
How can I rewrite the strings that the output from the variable for the next program called in the script will have them in this form ? 'log.*.console.log' 'log.*.log'
I was trying sed and awk but somehow without success.
The whole script:
#!/bin/bash
if [ -z "$*" ] ; then
echo "USAGE: ./some text"
exit 1
else
echo "some text"
read varlogname
i=1
for file in $@
do
echo "Doing" $file
GTAR=$(gtar -xvf $file --wildcards --ignore-case --no-anchored "$varlogname")
for file in ${GTAR[*]}
do
mv $file $file"."${i}
i=$((i+1))
done
done
echo "Files extracted."
fi
exit 0
DaWe4444
(123 rep)
Apr 10, 2017, 08:10 AM
• Last activity: Apr 10, 2017, 09:01 AM
Showing page 1 of 20 total questions