I have an kemalcr based application server listening on
http://127.0.0.1:3000 - behind apache2.
when running the kemalcr-app locally everything is fine and static-files - e.g. /assets/stylesheets/styles.css is delivered perfectly.
but when deploying on a production host behind apache2 - requests for the style.css will result in 404
My apache config for the virtual host looks like this:
<VirtualHost *:80>
ServerName mydom.com
ServerAdmin hostmaster#mydom.com
ErrorLog ${APACHE_LOG_DIR}/mydom_error.log
CustomLog ${APACHE_LOG_DIR}/mydom_access.log combined
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
When browsing $mydom.com kemal behind apache2 is responding fine - except for the static files.
My directory structure looks like:
app/
- src/
- spec/
- public/
- assets/
- stylesheets/
- styles.css
But a request for http://mydom.com/assets/stylesheets/styles.css results in 404.
Any ideas?
kemal app sets app-root where it is started from:
so, a capistrano deployment uses the home-directory of deployment user - which results in
/home/deployment_user
Kemal uses per default a relative path to public_folder './public'
This results in the public folder beeing resolved to
/home/deployment_user/public
which is - of course - not existing.
I can define the kemal-public_folder via config:
Kemal.config.public_folder = "/var/www/mydomain/current/public"
or define it according to Kemal.env e.g. 'production' or 'development'
Related
When I host a Next.js app on a test machine, the app loads as expected locally via the URL http://localhost:2301. Unfortunately, if I use Apache as a Reverse Proxy and try to access that same app externally via a URL like https://test-machine.example.com/test, I see numerous errors similar to these in my Browser Console:
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/chunks/webpack-61095c13c5984b221292.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/u5aVcss65ePhqhGxwvtAM/_ssgManifest.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/chunks/framework-64eb7138163e04c228e4.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/chunks/main-a3a79aff3ff232b41814.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/chunks/pages/_app-a8eaeefeae66525f4ca7.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/chunks/pages/index-e982999b584b9bc5ba94.js”. test:1:1
Loading failed for the <script> with source “https://test-machine.example.com/_next/static/u5aVcss65ePhqhGxwvtAM/_buildManifest.js”. test:1:1
I can confirm these files are on my test machine, but they reside in a hidden directory ".next" instead of a directory "_next" like the errors imply.
It doesn't seem to make any difference if I use the standard port 3000 or the new port 2301 that I am currently using. I get the same behavior whether I fire up a development instance of the site via "npm run dev" or a production instance via "npm run build; npm run start"
My Virtual Hosts File in conf.d looks similar to this:
<VirtualHost *:80>
ServerName test-machine.example.com
RewriteEngine on
RewriteRule .* https://test-machine.example.com [R=301,QSA,L]
</VirtualHost>
<VirtualHost *:443>
ServerName test-machine.example.com
SSLEngine on
SSLCertificateFile [myCertFileLocation]
SSLCertificateKeyFile [myCertKeyLocation]
SSLCertificateChainFile [myChainFileLocation]
DocumentRoot /var/www/html/test-dir
ProxyRequests off
ProxyPass /test http://localhost:2301
ProxyPassReverse /test http://localhost:2301
</VirtualHost>
How do I fix my Apache Reverse Proxy to correctly serve the files in the ".next/static" directory tree to my external browser clients?
Here is a workable solution:
Create a next.config.js file that looks like this:
module.exports = {
basePath: '/test',
}
Now modify your localhost proxy entry in Apache's VHost conf file to reflect the changes to the basePath as such:
<Location "/test">
ProxyPreserveHost On
ProxyPass http://localhost:2301/test
ProxyPassReverse http://localhost:2301/test
</Location>
This will ensure that the "virtual directory" and the directory that next.js uses as the project root are the same and the proxy works as intended. I like to use the <Location> tag to define the scope of the proxy in case I need to add any Rewrite or Redirects or exclusions therein. Notice the use of the Location tag changes the syntax of ProxyPass and ProxyPassReverse
I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html. I have not registered an official domain but setup /etc/hosts/ to resolve example.com to the IP address of my server.
I created another conf file called example.conf under /etc/apache2/sites-available and enabled it with sudo a2ensite example.conf and disabled the 000-default.conf.
Now whenever I go to example.com in my browser I get served:
.
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html I get served the correct index.html.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/ as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
I have a server and registered a domain - say mysite.com - that is pointing to the IP address of the server. I tested the setup with a django project in the default.conf file. This works without a flaw, but my goal is to move this django site to a subdomain. As this didn't work as expected, I tried to get a minimal example working with a redirect.
This is what I have:
sites-available/sub.conf
<VirtualHost *:80>
ServerName sub.mysite.com
RedirectPermanent / https://google.com/
</VirtualHost>
I enabled the site via a2ensite sub and service apache2 reload. When visiting sub.mysite.com all get is
Server not found
What am I missing?
I use Play framework and Apache as proxy.
My Play app runs at port: 9000
My Apache runs at portt: 9999
I config the Apache to serve as proxy as follows:
<VirtualHost *:9999>
ProxyPreserveHost On
ServerName localhost
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
Everything works fine.
However, when I add images to Apache root folder like this:
htdocs/a_folder/pic.jpg
Then, in my Play app, I load the image like this:
http://localhost:9999/a_folder/pic.jpg
The image does not get displayed and the request on the browser run forever.
How can I config the Apache to load static images (and might be other resources)?
You should reference the static assets with an /excluded/ prefix and set an Alias for /excluded/ that points to your existing documentroot. Otherwise, exclude /a_folder/ the same way /excluded is in line 4 of your code block.
I have Apache 2.2.15 configured with Mod_Proxy and Mod_SSL and serving CherryPy web application on RHEL 6.3. The only thing I'm struggling with is getting Apache to serve the website's static content (*.js, *.css, *.jpg). Here is my VirtualHost entry...
<VirtualHost mydomain.com:443>
ServerAdmin support#mydomain.com
ServerName mydomain.com
ProxyPreserveHost On
SSLProxyEngine On
DocumentRoot /var/www/html/mydomain
SSLEngine on
SSLCertificateKeyFile /etc/ssl/myserver.key
SSLCertificateFile /etc/ssl/mydomain_com.crt
SSLCertificateChainFile /etc/ssl/mydomain_com.ca-bundle
# this prevents the follow URL path from being proxied
ProxyPass static/ !
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://www.mydomain.com:8080/
ProxyPassReverse / http://www.mydomain.com:8080/
</VirtualHost>
For instance the path to my css file is the following...
/var/www/html/mydomain/static/style.css
Since I'm forcing the entire site to be in https when I navigate to
https://www.mydomain.com/static/style.css
or
http://www.mydomain.com/static/style.css
My browser tells me the page is not found (404). Can anyone see what I'm doing wrong?
EDIT:
it appears that Apache is still proxying /static... I found this redirect when accessing the /static/style.css in my Apache access log...
xxx.xxx.xxx.xxx - - [17/Sep/2012:08:46:06 -0400] "GET /static/style.css HTTP/1.1" 301 337 "https://www.mydmain.com/Home/" "Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120826 Firefox/10.0.7"
anyone know why that is happening?
Thanks in advance!
Andrew
Try adding an alias for your static folder before ProxyPass. It worked like champ for me,
Alias /static/ /var/www/html/mydomain/static/
If the static files are under the "main" source folder, I'd suggest telling CherryPy to serve the specific folder(s) for stylesheets, images, js etc
Personally I generate the config and then use that config when mounting the application like:
app = cherrypy.tree.mount(Root(), script_name="", config=somefile.get_config())
An example of static file serving with CherryPy.
The /css is the path that you use from within your templates or
HTML.
The os.path.abspath(os.path.join(os.path.dirname(__file__) generates a path pointing to your index file (or some other script if your not starting quickstart() from within the index)
The above path is then followed by the relative path to your static content folder
File:
##somefile
def get_config():
return {
'/':
{
'tools.encode.on': True,
'tools.encode.encoding': 'UTF-8'
},
'/css':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath(os.path.join(os.path.dirname(__file__), 'relative/path/to/your/css/folder'))
},
'/js':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath(os.path.join(os.path.dirname(__file__), 'relative/path/to/your/js/folder'))
}
}