Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Wednesday, 27 August 2025

TCP/IP Proxy Pass VS HTTP Reverse proxy

 HTTP Reverse Proxy

Application layer, cant present proxy destination certificate cause TLS handshake already being done at host

apache can only do HTTP reverse proxy




TCP/IP proxy pass

reverse proxy tcp packet, will present server certificate at destination instead of host,

Nginx can do it, go can do it

Nginx:

stream {

  map $ssl_preread_server_name $target {

    example.com 10.0.0.12:443;  # Server B

    default     10.0.0.11:443;  # Server A

  }

  server {

    listen 443;

    proxy_pass $target;

    ssl_preread on;

  }

}

Wednesday, 13 April 2022

Apach2 Allow CORS

 https://ubiq.co/tech-blog/enable-cors-apache-web-server/#:~:text=By%20default%2C%20cross%20domain%20requests,Origin%20Resource%20Sharing)%20in%20Apache.


sudo a2enmod headers
<VirtualHost *:443>
   ...
   Header add Access-Control-Allow-Origin "*"
   ...
</VirtualHost>

https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work

// For sites need to specify ports

Access-Control-Allow-Origin: http://siteA.com 



systemctl restart apache2.service    

Wednesday, 15 December 2021

How to set apache subversion

 https://www.howtoforge.com/tutorial/subversion-svn-with-apache-and-letsencrypt-on-centos/

Tuesday, 14 December 2021

Apahce2 /var/log/apache2 is written by root user by default && /var/log/mysql is written by mysql user

 https://serverfault.com/questions/905170/does-root-write-the-logs-in-a-default-apache-installation

Apache2

In the default Apache installation, all log files in /var/log/apache2 are written by root user. This is a security measure as it protects anyone from writing or gain access to the directory. It is recommended to not change the owner to www-data.

The Apache process running as root is responsible for writing the logs.



https://dba.stackexchange.com/questions/121258/what-to-do-when-mysql-is-not-generating-any-logs-at-all-on-debian


Mysql


Thanks to commenters for their insights. The solutions was:

  1. Add "log_errors = /var/log/mysql/mysql.err" to my.cnf
  2. See permissions error in error log
  3. chmod log files to "mysql:root"

Monday, 13 December 2021

Ubuntu - Disk Full - Delete files and Caution && apache2 && mysql failed to start due to /var/log removal

https://askubuntu.com/questions/1113629/apache2-service-failed-to-run-start-task-no-space-left-on-device 

When Ubuntu is full, apache will fail to start.


Should delete content in /tmp and /var/log (tmp are removed after reboot)


https://askubuntu.com/questions/171678/can-i-delete-var-log-files-due-to-low-root-space

However, if you delete the /var/log subdirectories. I deleted all my log files and their directories (rm -r /var/log/*) and it broke my apache2 functionality. Apparently apache doesn't/can't recreate the log directories and therefore can't write log files and that apparently can cause it to fail.

I've heard before that deleting some log files can cause problems, though I don't have any first-hand experience to support it. But of course I didn't have any first-hand experience of directory deletion being a problem until a few days ago...


Fix:

Create sudo mkdir apache2 in /var/log

https://askubuntu.com/questions/64996/var-log-apache2-gets-deleted-on-restart-so-apache-doesnt-start-on-startup



MYSQL fail to start due to /var/log removal (AKA showing permission denied error on sudo service mysql start)


1) sudo service mysql status

2) sudo service mysql stop

3) sudo service mysql start

5) vim  journalctl -xe to see log on why mysql failed

6) You should see cant access /var/log/mysql/error.log

7) sudo mkdir /var/log/mysql, sudo touch /var/log/mysql/error.log

8) ch


Wednesday, 18 August 2021

Lets Encrypt Error since June 2021 The server experienced an internal error :: ACMEv1 is deprecated and you can no longer get certificates from this endpoint.

Error : 

The server experienced an internal error :: ACMEv1 is deprecated and you can no longer get certificates from this endpoint. Please use the ACMEv2 endpoint, you may need to update your ACME client software to do so. Visit https://community.letsencrypt.org/t/end-of-life-plan-for-acmev1/88430/27 for more information.


Solution :

sudo apt-get install --only-upgrade certbot


https://community.letsencrypt.org/t/the-server-experienced-an-internal-error-acmev1-brownout-in-progress/148357/7


Monday, 7 June 2021

Apache default directory access, and how to allow for other directory access

 By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.

The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.



Allow more directory access :

 vim /etc/apache2/apache2.conf.

Require all grant meaning allow access

Options FollowSymLinks means symbolic link can be established


<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>





wq!

sudo service apache2 restart


// If only want /var/www access , can set up folderA in /var/www for symlink access to other directory, need to 


https://askubuntu.com/questions/843740/how-to-create-a-symbolic-link-in-a-linux-directory


ln -s /var/www/vhosts/ecash_cfe /var/www/vhosts/ecash-staging.com/ecash_root
  • -s stands for symbolic link

  • /var/www/vhosts/ecash_cfe is the source file

  • /var/www/vhosts/ecash-staging.com/ecash_root is the link name


Friday, 13 March 2020

Tuesday, 7 January 2020

Apache2 SSL does not work on server or AWS

1. Check if apache2 listens 443
netstat -ntupl | grep :443
https://bobcares.com/blog/apache-not-listening-on-port-443/

2. Check if apache2 port conf
Apache2 either put listen 80 on virtual host config file /etc/apache2/sites-available/000-default.conf and listen 443 on virtual host config file /etc/apache2/sites-available/default-ssl.conf 
or at /etc/apache2/ports.conf
If not add listen 443
the listen 443 statement is usually wrapped around in <if statement
<IfModule  ssl_module>
listen 443>
</IfModule>
3. Check if ssl_module installed
dpkg -S mod_ssl.so
Should show something like :
apache2.2-common: /usr/lib/apache2/modules/mod_ssl.so
then enable the module a2enmod ssl

then restart sudo service restart apache2
if not install :
install the ssl_module by:(99% time the ssl_modl comes with apache2 server)
apt-get install mod_ssl

https://serverfault.com/questions/446328/aws-installing-mod-ssl-on-apache


Also check on AWS networksecurity group to ensure port 80 and 443 are enabled for incoming traffic:

HTTP
TCP
80
0.0.0.0/0
HTTP
TCP
80
::/0
HTTPS
TCP
443
0.0.0.0/0
HTTPS
TCP
443
::/0

Wednesday, 23 October 2019

2021 Apache2 remove .html ending on website

webpage redirect to index page should just be / instead of index.html
the following rewrite does not require to change all redirect links from xxx.html to xxx at all
just change the redirect to index.html to /


Errors :
"htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration"
a)check apache error log
b)vim /var/log/apache2/error.log

Enable  rewrite module
a2enmod rewrite
systemctl restart apache2


!!!!! When below procedure is done, makesure to clean browser cache @2021 to see effect, use inspector then right click refresh, then click empty cache and hard reload
1) Check apache2 config

  • Go to /etc/apache2/apache2.conf 
  • edit <Directory /var/www>....
    • to be 

              <Directory /var/www/>
                  Options Indexes FollowSymLinks
                  AllowOverride All // allow .htacess override
                 Require all granted
             </Directory>
Restart apache2
sudo service apache2 restart


2) create .htaccess file in your /var/www/domain(that services website)

and add
RewriteEngine on


RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

to the file

// This does not require to remove any .html links in your web page
https://stackoverflow.com/questions/5730092/how-to-remove-html-from-url

.htaccese file need read permission by webserver



 https://stackoverflow.com/questions/5730092/how-to-remove-html-from-url


Go daddy lamp server :
In .htaccess file change the following :


#example.com/page will display the contents of example.com/page.html

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.html -f

RewriteRule ^(.+)$ $1.html [L,QSA]



#301 from example.com/page.html to example.com/page

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/

RewriteRule ^(.*)\.html$ /$1 [R=301,L]




For Godaddy add:



 Options -MultiViews



For http to https redirect



RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTP_HOST} ^(www\.)?citycentreupcc\.ca

RewriteRule ^(.*)$ https://www.citycentreupcc.ca/$1 [R,L]




Full code 

Options -MultiViews

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?citycentreupcc\.ca
RewriteRule ^(.*)$ https://www.citycentreupcc.ca/$1 [R,L]


#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/

RewriteRule ^(.*)\.html$ /$1 [R=301,L]