Is there a way to use this, or something like it, for SSL enabled hosts?
VirtualDocumentRoot /www/vhosts/%0/public
I want to avoid having to configure Apache every time I start working with a new domain on my development box. It would be nice to just add a directory, follow standard naming conventions, and be able to automatically access the site with HTTP or HTTPS.
I realize this definitely isn't the route to go for a production server, but it should be ok just for development.
One example came pretty close using mod_rewrite, but it still requires updating a configuration mapping file when you add a host (which I'm trying to avoid).
http://sweon.net/2008/01/hosting-multiple-ssl-vhosts-on-a-single-ipportcertificate-with-apache2.
Any ideas?
Thanks
The author of the article I referenced above was nice enough to come up with a solution.
This is working on Apache 2.2:
RewriteRule ^/(.*)$ /var/www/%{HTTP_HOST}/htdocs/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
Related
I've just reset my Ubuntu 14.04 LAMP server hosted with digital ocean. Could someone tell me the 'proper' way to do server configuration. My goal is to do everything as clean as possible (and hopefully well structured).
I intend on using the server mainly for programming and data analytics, however I do plan on hosting my website in /var/www/html. I also plan on using letsencrypt/certbot to get an easy SSL. With this in mind, these are the main goals I would like to accomplish:
1) Redirect the website to ALWAYS be served through https AND www.
2) Enable HSTS for the entire website.
3) Enable clean url's (remove .php extensions and what not).
Since I would like all of these properties to be used across the entire website, should the configuration be done inside of the /etc/apache2/ folder? Or should it be done inside of .htaccess?
And if it should be done inside of apache2 configuration, which file should I add it to? And finally, how exactly should it be added? (for example vhost 80/443, inside of a mod_something section, etc).
Thank you in advance, I would appreciate and consider any advice about Apache and htaccess!
I am currently migrating my website from Apache to nginx, but my .htaccess file is not working. My website is inside the /usr/share/nginx/html/mywebsite folder. How can I use .htaccess in my nginx server?
This is my .htaccess file:
RewriteEngine on
RewriteRule video/watch/([a-zA-Z0-9_#$*-]+)/?$ "videos-single.php?id=$1" [NC]
Nginx doesn't support .htaccess (see here: "You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.").
You've two choices (as I know):
import your .htaccess to nginx.conf (maybe the htaccess to nginx converter helps you)
use authd-htpasswd (I didn't try it)
Disclosure: I am the author of htaccess for nginx, which is now open source software.
Over the past years, I created a plugin which implements htaccess behaviour into nginx, especially things like RewriteRule, Allow and Deny, which can be crucial for web security. The plugin is used in my own productive environments without a problem.
I totally share the point of efficiency and speed in nginx, and why they didn't implement htaccess.
However, think about it. You cannot make it worse if you're using nginx plus htaccess. You still keep the great performance of nginx, plus you can drive your legacy appliances effortlessly on one webserver.
This is not supported officially in nginx. If you need this kind of functionality you will need to use Apache or some other http server which supports it.
That said, the official nginx reasoning is flawed because it conflates what users want to do with the way it is done. For example, nginx could easily check the directories only every 10 seconds / minute or so, or it could use inotify and similar mechanisms. This would avoid the need to check it on every request... But knowing that doesn't help you. :)
You could get around this limitation by writing a script that would wait for nginx config files to appear and then copy them to /etc/nginx/conf.d/. However there might be some security implications - as there is no native support for .htaccess in nginx, there is also no support for limiting allowed configuration directives in config files. YMMV.
Using the config file is one option, but the cool thing about the .htaccess file is that it provided a way for a web developer to have some control over server settings without having root access to the server. There doesn't seem to be anything like this on nginx which is a real bummer.
I understand how the way it's setup on apache slows down response times, but hoped there could be an nginx way to do the same thing without the performance hit... At least a way to do rewrites with regex on urls if nothing else.
"Is there no nginx way to do bulk redirects using regular expressions that doesn't slow down response times."
Just edit your database with myphpmyadmin.
Open myphpmyadmin select your database then find your "yourprefix_Posts" table.
Open it then click the "Search" tab, then "Find and Replace".
Select "post_content" in the dropdown
In the "Find" field, type URL you want to change: "website.com/oldURL".
In the "Replace" field, type the new URL: "website.com/newURL".
(To use regular expression, tick the "Regular Expression" box.)
NOTE: You can test this out by simply leaving the "Replace" field blank.
ALWAYS BACKUP database before making changes. This might sound scary but its really not. Its super simple and can be used to quickly replace just about anbything.
I have configured Jboss7 on Openshift yesterday. All I need to have an internal rewrite rule to have /members.html -> members.jsp.
This requires user to see members.html while the actual file(members.jsp) is served by Jboss itself.
Dont know correctly how to setup mod_jk if required but surely I would like this thing to work anyways as I have urls submitted in google and shifting site on openshift should not require me to change the URLs.
I don't think you have access to the Apache configuration on the server. You would need root permissions for that. Have you considered an alternative approach via a web application filter. There is UrlRewriteFilter - http://tuckey.org/urlrewrite/ - which might solve your problem.
I'm just starting to learn web dev, but got myself a bit confused when setting up my local development environment.
I had a php site on shared hosting for some time. I would edit local files and upload them, then refresh to ensure everything worked. A naughty practice I know!
So I have tried to set up a local dev environment and installed AMPPS for a local webserver (PHP5).
I have ambitiously set up the folder structure below so that I can code up a range of websites to try out different languages and frameworks whilst keeping them all seperate. (Square brackets denote folders). Note sure if this is the correct approach... (?)
-->[PHP]
---> [AMPPS]
----> [www]
-----> [PROJECTS]
------> [project_name]
-------> index.php
-------> .htaccess
-------> [images]
-------> [section1]
--------> page1.php
-------> [etc...]
------> [project_name]
------> [project_name]
--> [RUBY]
--> [PYTHON]
My first hurdle however is that all of my links were relative, and I had of course uploaded my site at root with my host. Root in my local dev enironment is now www, which as you can see is several folders up from where I have installed my site.
Links (e.g. Page 1) now display as: "localhost/section1/page1.php" when I believe they should in fact show as "localhost/PROJECTS/project_name/section1/page1.php".
I don't think that telling APACHE that my root directory is [project_name] is the correct approach, because then it wont work for other projects I create. I assume that I should be doing something on a project by project basis to specify it's own root directory.
I thought that I could specify root by adding an .htaccess file to the project_name folder:
From my online research I thought it would go something like:
RewriteEngine on
RewriteRule ^/$ /PROJECTS/project_name/
or perhaps
RewriteEngine on
RewriteRule ^/$ .;C/PHP/AMPSS/www/PROJECTS/project_name/
However I can't get these to work.
When the site was online, I had also coded <?php set_include_path($_SERVER['DOCUMENT_ROOT']); //Look for includes starting from ROOT location ?> at the top every page, thinking I was doing the right thing.
Now I am not so sure that I correctly understood what I was doing there. It doesn't seem to have any impact with or without it in my development environment. And I haven't been able to edit it in any way successfully to resolve my relative links issue.
Sorry for the long post.
I'm grateful for any and all feedback/assistance. Thanks in advance :)
[Resolved] - The advice below was perfect. Thank you all. :)
A tip for Chrome users:
If you are using a custom domain, like I did with .dev, either proceed the address with http://, or end it with a trailing /.
For example I now visit my dev site in Chrome by visiting projectname.dev/ (without the last / it tries to search).
At first I thought I had set up VirtualHost or hosts incorrectly, when in reality it was this Chrome behaviour that that was clouding the issue. At the time of writing, other browsers like Firefox don't share this concern.
Hope that helps someone else out.
You're correct that configuring Apache for each project is the way forward. It's best done with virtual hosts. Define a virtual host for each project and give it a domain name or subdomain for development. In my case I use test.com for all my local development and configure project1.test.com, project2.test.com etc so all my relative paths work as expected. For this I also edit my hosts file so the DNS lookup for test.com and sub projects resolve to my local machine.
Rewriting URLs is something I reserve for a project-by-project basis, without setting global rewrites for a specific server setup. That way my local development environment is close to the actual server environment and project-specific rewrites will work as expected.
Hope that helps
I recommend using method mentioned by #Tak, but I know there might be problems with pre-configured WAMP packs to add virtual hosts, so there is also a solution to use BASE tag in head section of your html:
<base href="http://localhost/PROJECTS/project_name/">
I have an existing web application which I have been building with an ant script and deploying as a .war file to Tomcat.
I am trying to add Drupal to my current technology stack to provide CMS and general UI-related functionality so that I don't have to write my html pages by hand and rather use templates.
During the installation of Drupal7, some of the instructions suggest that I go to this directory:
/etc/apache2/sites-available
and change the DocumentRoot to
/home/myuser/drupal/drupal7
If I make the docroot a basic directory on the file system, how will this impact how the application will work? In addition to Apache, I also have Tomcat server. My goal is to get them to all play nice together. How is this best accomplished?
If I make the docroot a basic directory on the filesystem
I'm not sure what you mean by this. There's no qualitative difference between /var/www and /home/mysuser/drupal/drupal7. The latter is longer and in the user's home directory, but assuming this user would be administering the service anyway that doesn't matter.
Next, the best way to make Tomcat and Apache get along is probably to run one of them on different subdomains. You could use the same domain, but that'd mean you had to run one of the daemons off a nonstandard port and that looks strange and might run into firewall trouble with some users.