Apache on CentOS issue configuring routing to "Index.html" (uppercase"I") - linux

I have a project being deployed such that an Apache instance is running on CentOS (DMZ) which is due to forward all requests to a TOMCAT instance running behind the firewall. For instance, a request:
www.Example.com
needs to be forwarded to:
HTTP://<servername behind the firewall>:<port number>/Blabla/Index.html
(Note that Index.html has a capital I).
I should note that the whole project required extensive review as it was developed under Windows (case insensitive filenames) but the running environment is Linux, and now all filenames and their references are fully synchronized.
The problem appears to be that it is not possible to configure within Apache to forward requests to Index.html and it converts it to index.html, which does not exist.
I can change all the file names to lowercase, but this will take quite some effort.
Is there any way to force Apache to use as-is what I define (i.e. if lowercase, use lowercase; if uppercase, use uppercase; if mixed, use mixed).
Thanks in advance.

You should be able to use mod_speling from Apache. In your configuration file, simply put:
CheckSpelling On
CheckCaseOnly On
And reload Apache using either:
/etc/init.d/httpd reload
Or if you're using CentOS 7:
systemctl reload httpd
This should now make all the files in your website directory insensitive.

If you're using virtualhosts, you may add this option into it:
DirectoryIndex Index.html
So your virtualhost should be like that :
<VirtualHost *:80>
ServerName website_name
DocumentRoot website_directory
DirectoryIndex Index.html
</VirtualHost>
You can paste it in /etc/httpd/conf.d/mywebsite.conf and reload apache with :
systemctl reload httpd
If you have CentOS/7. For older versions of CentOS use this command:
service httpd reload

Related

How do I make apache2.4 configuration specific to a particular virtualhost so it doesn't affect other virtualhost on a centos server

I have put in my include file which is in this directory /etc/apache2/conf.d/userdata/std/2_4/myusername/sub.domain.com/proxy.conf.
On the file I did proxy reverse to localhost port 5000 for my net core app.
Then I did a post virtualhost include using include editor.
When I try to reach other domain on same VPS I get server temporarily unavailable to handle request error.but when I uncommented the proxy reverse on my include file i was able to reach other domain.
So my question is given the procedure I have taken, why is an include specified for a particular virtualhost affecting other virtualhosts on the server.
Proxy reverse code in the include file is code below
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/ ```
And this include was applied to virtualhost for the particular sub domain, don't know why it affects other virtualhosts.
Then I did a post virtualhost include using include editor.
If this means outside the <virtualhost> then its no wonder it affects all virtualhosts -- outside of <virtualhost> is global.
what i did was i opened up the post_virtualhost_global.conf file found in /etc/apache2/includes/.
then i removed the include statement from the post_virtualhost_global.conf file, then it worked, i dont seem to understand how, but it worked perfectly anyway. i have also applied same practice for subsequent virtualhost proxyreverse includes i have done afterward.

How to properly launch Angular Universal to live server

I have my website setup and working by modifying the universal-starter seed found here: https://github.com/angular/universal-starter and I have got my site working (rendering HTML) on the localhost node server, now I have a SSH connection and node installed, now I am here:
And I am not sure where I put my /dist files etc and then start the nodejs server.
NodeJS/npm installed shown here:
Edit (3/23/21): Something to be aware of when using Universal
You really need to consider writing blocks of code specifically for the Browser or for the Server. For example:
You might use an external SAAS solution (like SharpSpring or Google Tag Manager) to help your team track leads and generate automatic workflows.
Some of these services require you to write objects to either the window or document objects. Because your server isn't running javascript, there isn't a way to get these objects to behave like they would natively when running your application on the server. You will need to really mess around with these things.
A really helpful article I found was this demo of real app problems using Angular Universal.
You will also need to dynamically append imported scripts to your index.html header. I have seen this same concept a couple of different places, but here is one as well. There might be a stack overflow answer that has this same idea.
However, in some instances, you will need to use a library or something (like Postscribe) to dynamically add scripts to individual components inside of one of your html template files. Postscribe helped us drastically by allowing us to dynamically import a specific script in front of a form in one of our components. I highly recommend using Postscribe.
So, long story short, you will need to make sure you are importing scripts and appending them to your index.html file only if your application is running in the browser. Do this check for all external JS files as well that you are importing into your application and using directly. Start by injecting PLATFORM_ID into whatever component you need to make this check in, and using it that way
This applies to all kinds of things like animations (which might be listening to a window scroll event), etc.
Original post below:
#Cacoon I hope this is what you did.
This first part is an existing answer from m98 on this Github issue. Just posted here for clarity
Build your app: npm run build:ssr
Move the dist over to your server
install PM2 npm install pm2 -g
On your server, use PM2 to run the server bundled app pm2 start dist/server.js
If you're using Nginx, or other web servers, make sure to redirect requests to the port that the app started with PM2 is listening on.
UPDATE (2/7/2020)
For Apache make sure your document root is specified as your dist/browser folder like
DocumentRoot "${SRVROOT}/htdocs/dist/browser"
<Directory "${SRVROOT}/htdocs/dist/browser">
And try this in the bottom of your httpd.conf file:
<Location />
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html
</Location>
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
</VirtualHost>
<VirtualHost *:443>
ServerName localhost
ServerAlias localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / https://localhost:4000/
ProxyPassReverse / https://localhost:4000/
</VirtualHost>
You have to set the virtual host in the httpd.conf, and not in a .htaccess file. You can set Mod_rewrite at the same level of your index file in an .htaccess file, but you cannot set virtual host at that level.
Also, make sure you enable the modules for the proxy, like mod_proxy_express in your httpd.conf file
This is for developing locally. Change localhost to your domain when deploying to prod.
This was actually easier than it seemed, I just needed to install pm2 with npm so I could make the nodejs process constant, then use RewriteEngine settings in the .htaccess file where I wanted to my angular universal application to render (it was in a subdomain folder) and ensure the port is correct and it linked perfectly and loads html in source allowing proper SEO and indexing

Configure httpd.conf to add new site on Apache Red Hat Linux

I have linux server (Red Hat Enterprise Linux Server release 5.3 (Tikanga)) with apache installed. It is already used for browsing some documents. Now I would like to add a new Directory (with a html page), so whenever the directory is browsed it can display the html page.
But I am not sure of where all to edit the httpd.conf file
Existing httpd.conf:
When I hit the url "http://servername/eng" it displays list of folders.
Now, I want to add a website to this existing, so when user hit the url "http://servername/builds" it should display a html page in the browser.I have added my "index.html" page in location "/var/www/html/builds/"
For this I added the below code to httpd.conf file
Please let me know what all modifications are required in the conf file
You can do it in a few different ways.
Putting index.html in /build
This requires you to have this setting:
DirectoryIndex index.html
(it should be there by default on most platform.)
Also for this to work, rather than putting new <Directory>, you should put the build/ directory in the directory that holds your http://example.com/ files. For instance:
/var/www/example.com/public_html/eng/
/var/www/example.com/public_html/builds/
/var/www/example.com/public_html/builds/index.html
Storing build/ in folder completely unrelated to example.com, but still be able to reach it via example.com/builds
For this, you need to rewrite the URLs so that example.com/builds redirects the user to the final URL. This is most easily achieved through mod_rewrite. You enable mod_rewrite module in your Apache's configuration, make sure that example.com can have .htaccess files through ensuring proper AllowOverride entry in example.com's <Directory> configuration, create /var/www//example.com/public_html/.htaccess (or similar) file, and fill it RewriteEngine On and RewriteRules you need. More on mod_rewrite in the Internet and in the documentation.
Completely separate virtual server, for example builds.example.com/
In this case, what you're looking for are virtual servers. These are not defined in httpd.conf or configuration itself, but usually have dedicated directory.
For example, to add builds.example.com that works for port 80, you'd need to create following entry:
<VirtualHost *:80>
ServerName builds.example.com
DocumentRoot /var/www/builds.example.com/public_html/
</VirtualHost>
Where to put this? Well, it depends on the platform. For Debian, you put this in a new file in /etc/apache2/sites-available/, e.g. /etc/apache2/sites-available/example.com, and symlink to it in /etc/apache2/sites-available (on Debian, you can do this easily with a2ensite <NAME_OF_FILE>. On your platform this procedure might be different, so look it up ("adding virtual servers on " would be a start). After adding virtual servers, you need to reload your Apache configuration.
Please let me know if this satisfies your question, if not, I'll edit the answer accordingly.

PHP files are downloaded by browser instead of processed by apache2 after creating virtual hosts

I created a virtual host in apache2 (LAMP) as shown below and the php files are downloaded by the browser instead of processed by apache. I created an HTML file and it worked.
/var/www/myvirtualhost.com/public_html
ServerAdmin webmaster#localhost.com
DocumentRoot /var/www/myvirtualhost/public_html/
ServerName myvistualhost
Check this question out. It's for Apache on Ubuntu, and you don't specify what system you are on, but maybe you can get a tip from there.
Basically it describe how to install the PHP module for Apache, which is probably not installed if PHP-files are downloaded.

How to Setup Website Directory (Custom Host) on Centos 7

I'm trying to figure out how to have the website function after i point the DNS to the server.
by default, (after fresh install of apache, mysql, php) the main server directory is situated at var/www/html so if i upload test html file, via default server ip the html file will show.
i'm trying to setup a custom folder i.e var/www/examplewebsite.com/public_html and then the public_html would function as the go-to folder for when user goes to my website. Multiple websites on one IP (server) would be great too
i found some information from http://bit.ly/1kguprn but i do not see the NameVirtualHost and the paragraph under that.
I'm a newbie to the Centos/Linux environment, any help would be greatly appreciated :)
You have a nice tutorial here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6
Basically, create a folder and an index for testing purposes:
sudo vi /var/www/example.com/public_html/index.html
add the Virtual directive in your apache config file (:
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /var/www/example.com/public_html
ServerName www.example.com
ServerAlias example.com
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/requests.log
</VirtualHost>
Restart apache:
sudo service httpd restart
Check this documentation for Centos 7. They have a nice initial tutorial.
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-2-files-and-processes
First, I will recommend to you that check if you have the httpd service installed and active.
sudo service httpd status
if non active
sudo service httpd start
once active
Check the if the ports 80 and 443 (https are active)
sudo netstat -tulnap | grep :80
sudo netstat -tulnap | grep :443
if they are active, test the server. http://yourserverip or https://yourserverip
By default it should go to the apache webserver page.
Once you can see the page. Try to create the initial index.html page in
/var/www/html
vi /var/www.html/index.html
click i for insert
copy the following html
Test
Test web page
In the tutorial, they will explain the rest of the configuration.
#Moderator The tutorial provide a good long material for the reader, I got punish for answer correctly by the moderator. I think the website are long enough to clarify the question and I think copy again the tutorial here is not proper answer.
Also check the next documentation for changes between Apache 2.2 and 2.4
https://linode.com/docs/security/upgrading/updating-virtual-host-settings-from-apache-2-2-to-apache-2-4/
If you have any problems, comment here.

Resources