I have a Docker container with wordpress:latest in a host which has Apache 2.4 installed.
I added the lines below to my Apache configuration file, inside the vhost group:
ProxyPass http://localhost:8010
ProxyPassReverse http://localhost:8010
When I try to access my URL I can reach wordpress homepage, however all static files point to localhost so my layout doesn't work.
What am I missing? Some setup at Apache? Wordpress itself?
Apache modules are already enabled.
Edit 1:
Forgot to mention: this piece of configuration is inside a Location directive, which is inside a vhost directive.
<VirtualHost *:80>
...
<Location /usa>
RequestHeader set X-Is-Reverse=Proxy true
RequestHeader set X-Original-Host mysite.com.br
ProxyPass http://localhost:8010
ProxyPreserveHost On
ProxyPassReverse http://localhost:8010
</Location>
...
</VirtualHost>
Check that the Site URL setting in wordpress matches the URL your clients are calling.
This is the documentation on how to change the site URL in wordpress: https://codex.wordpress.org/Changing_The_Site_URL
If you proxy pass to your backend like that, requests coming into your container will be sent with the Host header set to localhost. Apparently, the WordPress container takes care of the host that has been set in order to generate static assets links. Try setting the following proxy option:
ProxyPreserveHost On
Just after the ProxyPass configuration line.
This options forward the Host HTTP header coming from the client over to the proxy connection. This way the backend will understand which public URL it's been called from and asset links should be correct.
Edit.
If you can't use the ProxyPreserveHost Directive you could try and directly set the Host header using:
RequestHeader set Host "your.host.name"
Related
UBUNTU + APACHE
I am running a few wordpress sites on one server (that I inherited) using VirtualHosts, and I need to configure ssl certificates for each site.
Before starting to set up certificates for each site, I tried entering each domain with the https prefix on the browser and noticed it redirects me to a site (with an invalid certificate) that is supposed to be disabled and does even show up when I run
apachectl -t -D DUMP_VHOSTS
I tried configuring the virtualhost entries for one of the sites with the valid certificate and it still goes to same old site. How can I completely disable and remove that site and the invalid certificate? I cannot find it anywhere on the server.
My Virtual host looks something like this
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.yoursite.com
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /path/to/www_yoursite_com.crt
SSLCertificateKeyFile /path/to/www_yoursite_com.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>
If you want to disable a virtual host configuration you just need to do:
sudo a2dissite sitename
sudo systemctl restart apache2
and the issue should be resolved
I work on one website which is travel blog and there is sub section mytravelsite.com/tickets which is whitelabel and everything under that mytravelsite.com/tickets/fares and other pages are pointing to another ip and this works fine.
But now i would like to switch and now main site to be mytravelsite.com which would be whitelabel from mytravelsite.com/tickets but without /tickets in url but still keep my blog so another trouble is that whitelabel don't have robots.txt so this i would have to serve too from my hosting.
So in the end i have hosting with 10.1.1.1 ip and whitelabel that resolve to 10.10.10.10 ip
What i need is:
everything under mytravelsite.com/blog to resolve to my hosting and my hosted website on 10.1.1.1
and also mytravelsite.com/robots.txt and mytravelsite.com/sitemap.xml to resolve to my hosting on 10.1.1.1
and everything else to resolve to the whitelabel at 10.10.10.10
i am guessing that this can be done either with some dns setup or nginx proxy or rewrite rules but everything i searched on internet for last 2 days ended up in failure.
DNS only considers the name, i.e. the part before the slash. You have always mytravelsite.com, so this can't be done purely in DNS.
I know this isn't a real/full answer.
I would try to solve it using proxy.
The included snippet is not a configuration of nginx but of an apache as I don't have similar setup for nginx within my reach now. But I believe it can be useful starting point though.
<VirtualHost 10.10.10.10:80>
ServerName mytravelsite.com
ProxyPreserveHost On
ProxyPass /blog/ http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /blog/ http://10.1.1.1/
ProxyPass /robots.txt http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /robots.txt http://10.1.1.1/
ProxyPass /sitemap.xml http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /sitemap.xml http://10.1.1.1/
</VirtualHost>
Notes:
10.*.*.* is a local-only network, so the 10.10.10.10 within the
virtualhost header is just for an illustration on what server this
definition should be put.
It also will not be working out of the box - just start here and
iterate to a final solution
You have not defined how could "your hosted website" be identified, therefore it is missing in the example
I created website on Amazon Web Server. I route my ip to my domain using ROUTE 53 service. but now my website is showing APACHE TEST PAGE rather then content while if i enter my ip address/wordpress it's working properly.
Any solution please?
maybe you forgot to add a virtual host in http.conf. Apache restart is needed after this.
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
# Other directives here
</VirtualHost>
https://httpd.apache.org/docs/2.4/vhosts/examples.html
I've been trying to set up a reverse proxy on a main website to a blog site of the url format
example.com/blog -> blog.example.com
example.com/blog is on an Apache instance and in the httpd.conf I have added the following.
SSLProxyEngine on
ProxyPreserveHost Off
ProxyRequests Off
ProxyPassMatch /blog https://blog.example.com
ProxyPassReverse /blog https://blog.example.com
This all works but it keeps 404ing. The good news is it is actually reverse proxying correctly because it grabs the 404 page of the blog.
After looking at the apache access logs I found that it is passing the subpath for whatever reason /blog to blog.example.com so its fetching blog.example.com/blog. When users navigate to /blog, it does 404 naturally. However, my understanding was when setting up ProxyPassReverse is it would make the request at what was specified so in my above case it should be requesting blog.example.com and not passing the /blog at the end.
Here is the snippet from the documentation that confirms the above in how it should work:
For example, suppose the local server has address http://example.com/; then
ProxyPass /mirror/foo/ http://backend.example.com/
ProxyPassReverse /mirror/foo/ http://backend.example.com/
ProxyPassReverseCookieDomain backend.example.com public.example.com
ProxyPassReverseCookiePath / /mirror/foo/
will not only cause a local request for the http://example.com/mirror/foo/bar to be internally converted into a proxy request to http://backend.example.com/bar (the functionality which ProxyPass provides here).
Any ideas why this might be? Worst case I might try to add a redirect or a rewrite so /blog goes to the homepage but I do have my permalinks set up in such a way that the /blog is in the slug of articles.
FYI I am using Apache 2.2.
I'm an idiot. I was using ProxyPassMatch instead of ProxyPass. Ugh.
How does a web server recognize which URL to serve when there are multiple web sites (hostnames) associated with the same IP address?
With the Apache web server, a set of virtualhosts is defined that contain parameters to match a request to a directory. Using a basic, default set up for an Ubuntu web server, you would have a file in the /etc/apache2/sites-enabled directory like this:
<VirtualHost>
ServerName example.com
DocumentRoot /var/www/example.com/httpdocs
</VirtualHost>
This tells apache that all requests to example.com that arrive at this machine should be routed to the /var/www/example.com/httpdocs folder. Another entry to example.org could point it to a different folder.
Also relevant is the /etc/hosts file and the apache a2ensite command.
This is done in apache by using NameVirtualHost
You first declare what IP and port in httpd.conf to use like:
NameVirtualHost 127.0.0.1:80
Then in your virtual host block, you do:
<VirtualHost 127.0.0.1:80>
ServerName your_domain
DocumentRoot path_to_your_app
....
</VirtualHost>
This will allow you to have multiple hosts on one IP. But be warned that if you access the IP directly, it will direct the request to the first virtual host.
Through the use of virtual hosts.
This is an example configuration from nginx
http {
index index.html;
server {
server_name www.domain1.com;
access_log logs/domain1.access.log main;
root /var/www/domain1.com/htdocs;
}
server {
server_name www.domain2.com;
access_log logs/domain2.access.log main;
root /var/www/domain2.com/htdocs;
}
}
Essentially, when a user requests a resource the server checks the host field of the request and responds accordingly.
HTTP 1.1 defines a header called the "Host" header.
Before Apache or any other server sees the request, the client browser creates the http 1.1 request headers and sends the request to the server you are asking for your browser to contact.
Once the request hits apache the server looks at the Host header portion of the HTTP request headers. You can observe this by using wireshark, liveHttpHeaders, HTTPfox or whatever http dissecting/packet capturing tool you like. The host header in HTTP 1.1 (Host: header is not defined for HTTP 1.0 or 0.9) is formatted as follows:
Host: www.example.com\r\n
When apache looks at this header it parses it and goes through the existing VirtualHosts table that is used for mapping matching host headers to directories or actions defined.
That is to say if you had a NameVirtualHost for www.example.com that points to /some/path/example.com/
NameVirtualhost stuff here
<VirtualHost 127.0.0.1:80>
ServerName www.example.com
DocumentRoot /some/path/example.com
....
</VirtualHost>
your apache would take the following request:
GET /index.html HTTP/1.1\r\n <-- version is a key part
Connection: close\r\n
Host: www.example.com\r\n <-- key part
Accept: blah\r\n
Another: blah\r\n
read the wiki page for more on header format.
Apache would see that the host header contains www.example.com and serve up the file
/some/path/example.com/index.html because that directory and filename matches the requested resource and it is the directory that is to be used for serving requests with the host header containing www.example.com.
That is how it works.
Depends on the type of server. Apache uses a .htaccess file and you could also configure virtual hosts. If you're trying to do something specific, you may want to edit your question to include exactly what you're looking for and what software you're using to host.