websocket protocol not supported trough Apache2 reverse proxy

we've set up a reverse proxy with apache2, in order to hide the port in the url. And in later stages secure our connection wih SSL.

We're running a Hawkbit java container on AWS ECR. We normally go to the service's webpage by entering ip:port/UI. Our internship mentor wants to be able to enter ip/UI to go to the webpage. We've set up a apache2 reverse proxy,and are able to go to the webpage with ip/UI.

However, when we log in as admin, we're not permitted to do anything. We've checked the traffic by using F12 on firefox, and we get a 501 error when trying to establish a websocket.

we're also using an application ELB on AWS.

we've tried to add the following to our conf file:

ProxyPass /UI ws://ip:port/UI ProxyPassReverse /UI ws://ip:port/UI

but with no effect.

hopefully someone can help us

Display custom error pages with PHP 7 – details for me, generic for users

Using Linux/Apache/PHP7, I want to display all error messages gracefully. I have my .htaccess file with the following:

ErrorDocument 400 /errors/error.php
ErrorDocument 401 /errors/error.php
ErrorDocument 403 /errors/error.php
ErrorDocument 404 /errors/error.php
ErrorDocument 500 /errors/error.php
ErrorDocument 502 /errors/error.php
ErrorDocument 504 /errors/error.php

...which points to a error.php page with the following:

$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
403 => array('403 Forbidden', 'The server has refused to fulfil your request.'),
404 => array('404 Not Found', 'The page you requested was not found on this server.'),
405 => array('405 Method Not Allowed', 'The method specified in the request is not allowed for the specified resource.'),
408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
502 => array('502 Bad Gateway', 'The server received an invalid response while trying to carry out the request.'),
504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);
$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
$message = 'Please supply a valid HTTP status code.';
}
echo '<h1>Hold up! '.$title.' detected</h1>
<p>'.$message.'</p>';

The 404 function seems to work just fine, but any php error like a typo in a function name still displays as a white screen with standard php error messages. Even an intentional typo in the .htaccess file produces a generic 500 error, but doesn't use the error.php page I established for this purpose.

What I'd like to do also is display the php error details for me, but hide the details for users, even when in production mode.

HTML 5 Playing Video Work with .txt but not .mp4

I am trying to use html5 to play video from apache on my Ubuntu 16.04 server. The issue is if I use .mp4 extension it will not load however if I use .txt as an extension it works fine.

I have tried adding mp4 to the mime/types with .htaccess with no luck

Doesn't Work

<video src="video.mp4" controls=""> </video>

Works

<video src="video.txt" controls=""> </video>

Error from Console

Failed to load resource: net::ERR_CONNECTION_RESET

Trying to call a PHP CLI script from a web script causes Apache to spawn multiple child processes

Having read loads of threads about calling a long-running PHP CLI script from a web script, and the best way to daemonize the CLI script, I have hit an insoluble problem with the way Apache handles the CLI script. According to this blog post, the best option is to do something like :

print `echo /usr/bin/php -q longThing.php | at now`;

When I do this on my local CentOS 7/PHP 7/Apache 2.4.6 VM, it works like a charm, however, the identical code on my production server Centos 6.8/PHP 7/Apache 2.4.25 (cPanel) causes Apache to spawn 100s of child processes, rapidly exhausting the CPU and memory resources, requiring a reboot to fix. Even if I quickly kill the PHP CLI process, Apache has already got itself into some kind of loop. My understanding was that by using the suggested code above, you disassociated Apache from the CLI process, but clearly not. Can anyone point me toward what is going wrong ? I can post the actual code and more details of my production server if needed. Thanks

Mod Evasion Email Notification Issue

We are attempting to set up Apache Mod Evasion to prevent future DOS attacks on one of our servers. Everything seems to be working well outside of email notifications. The stack is running PHP 7.1 and Apache2.4 on Ubuntu Server 16.04.

Email works fine via a test command:

sudo su - www-data -s /bin/bash -c 'echo "this is the body" | mail -s "Subject" [email protected] [email protected]'

Here is the mod evasion.conf:

<IfModule mod_evasive20.c>
    DOSHashTableSize    3097
    DOSPageCount        1
    DOSSiteCount        1
    DOSPageInterval     10
    DOSSiteInterval     10
    DOSBlockingPeriod   10

    DOSEmailNotify      root
    #DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
    DOSLogDir           "/var/log/mod_evasive"
</IfModule>

Here is the ssmtp.conf file:

[email protected]
FromLineOverride=YES

Debug=YES
UseSTARTTLS=YES
UseTLS=YES
mailhub=email-smtp.us-east-1.amazonaws.com:465
AuthUser=#######
AuthPass=#######
AuthMethod=LOGIN

Here is the revaliases file:

root:[email protected]:email-smtp.us-east-1.amazonaws.com:25
www-data:[email protected]:email-smtp.us-east-1.amazonaws.com:25

I am getting black background in Apache POI XSSF

I want to give a custom color to a row with different cells.

XSSFWorkbook wb = new XSSFWorkbook();
                String safeName = WorkbookUtil.createSafeSheetName("Main Result"); // returns " O'Brien's sales   "
                XSSFSheet sheet1 = wb.createSheet(safeName);

                XSSFCellStyle[] style=new XSSFCellStyle[12];
style[4] = (XSSFCellStyle)wb.createCellStyle();
                style[4].setFillBackgroundColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
                style[4].setFillPattern(CellStyle.BIG_SPOTS);

This code is working fine for some cells in a row. But, it's printing black colour background for other rows in the cell. Below are the functions where I am doing the core stuffs.

public static void merge(int i,int j,Sheet sheet1,ArrayList<Room> rooms)
    {
        sheet1.addMergedRegion(new CellRangeAddress(
                i, //first row (0-based)
                i+1, //last row  (0-based)
                j+1, //first column (0-based)
                j+3  //last column  (0-based)
        ));
        sheet1.addMergedRegion(new CellRangeAddress(
                i, //first row (0-based)
                i, //last row  (0-based)
                j+4, //first column (0-based)
                j+4+rooms.size()-1  //last column  (0-based)
        ));
    }

    public static void printRooms(int i,int j,Sheet sheet1,ArrayList<Room> rooms)
    {
        Row row2=sheet1.getRow(i+1);
        if(row2==null)
        row2=sheet1.createRow(i+1);
        for(int k=0;k<rooms.size();k++)
        {
            Cell cell=row2.createCell(j+4+k);
            cell.setCellValue(rooms.get(k).getRoom_no());
            //cell.setCellStyle(style[1]);
        }
    }
    //this function prints all the data in excel sheet for a particular SLOT and TIME INTERVAL
    public static void printInExcel(Map<Integer,String> batch_id_name,
            Map<Integer,Integer> line,Map<Integer,Integer> range,Sheet sheet1,int j,XSSFCellStyle[] style,Set<Course> set,TimeInterval t1,Workbook wb,int flag) throws ClassNotFoundException, DAOException, SQLException
    {
        int flag2=0;//to print labels just for first time.
        int border_first=0;
        int border_last=0;
        for(int batch_id=1;batch_id<=batch_id_name.size();batch_id++)
        {
            //check if such batch_id exists
            if(!line.containsKey(batch_id))
                continue;
            //Merge Rows

            int start=line.get(batch_id);
            int end=start+range.get(batch_id)-1;
            int i=start-2;
        //print default messages


            ArrayList<Room> rooms=GeneralDAO.getRooms();

            Row row1=sheet1.getRow(i);
            if(row1==null)
            row1 = sheet1.createRow(i);
            //if flag2==0,it means it's first iteration
            if(flag2==0)
            {   border_first=i;
                if(flag==1)
                {
                    //System.out.println("Working");
                    TimeTable.merge(i, j, sheet1, rooms);
                    row1.createCell(j+1).setCellValue(" 08:30 - 10:30 ");
                    row1.createCell(j+4).setCellValue(" CEP Rooms ");
                    TimeTable.printRooms(i, j, sheet1, rooms);
                    flag2=1;
                }
                else if(flag==2)
                {
                    TimeTable.merge(i, j, sheet1, rooms);
                    row1.createCell(j+1).setCellValue(" 11:00 - 13:00 ");
                    row1.createCell(j+4).setCellValue(" CEP Rooms ");
                    TimeTable.printRooms(i, j, sheet1, rooms);
                    flag2=1;
                }
                else if(flag==3)
                {   TimeTable.merge(i, j, sheet1, rooms);
                    row1.createCell(j+1).setCellValue(" 14:00 - 16:00 ");
                    row1.createCell(j+4).setCellValue(" CEP Rooms ");
                    TimeTable.printRooms(i, j, sheet1, rooms);
                    flag2=1;
                }
                else if(flag==4)
                {
                    TimeTable.merge(i, j, sheet1, rooms);
                    row1.createCell(j+1).setCellValue(" 16:30 - 18:30 ");
                    row1.createCell(j+4).setCellValue(" CEP Rooms ");
                    TimeTable.printRooms(i, j, sheet1, rooms);
                    flag2=1;
                }

            }

            Row row=sheet1.getRow(start);
            if(row==null)
                row=sheet1.createRow(start);
            //System.out.println("batch_id"+batch_id+"start: "+start+"end: "+end);

            if(flag==1)
            {
                if((end-start)!=0)
                {   
                sheet1.addMergedRegion(new CellRangeAddress(
                        start, //first row (0-based)
                        end, //last row  (0-based)
                        j, //first column (0-based)
                        j  //last column  (0-based)
                ));
                }
            // Write Batch Name

            row.createCell(j).setCellValue(batch_id_name.get(batch_id));
            row.getCell(j).setCellStyle(style[batch_id-1]);
            }
            //Start allocating courses
            for(Course course:set)
            {

                if(Integer.parseInt(course.getBatch())==batch_id)
                {
                     Row row_temp = sheet1.getRow(start);
                     if(row_temp==null)
                     {
                         row_temp=sheet1.createRow(start);
                     }

                        row_temp.createCell(j+1).setCellValue(course.getCourse_id());
                        row_temp.getCell(j+1).setCellStyle(style[batch_id-1]);
                        row_temp.createCell(j+2).setCellValue(course.getCourse_name());
                        row_temp.getCell(j+2).setCellStyle(style[batch_id-1]);
                       // sheet1.createRow(80).createCell(j+1).setCellStyle(style[10]);
                        ArrayList<Room> temp_rooms=t1.getRooms();
                         //first column for timeinterval1
                        int first_col=j+4;
                        for(int p=0;p<temp_rooms.size();p++)
                        {

                            System.out.println("Running"+p);

                            if(!t1.getMap().containsKey(temp_rooms.get(p).getRoom_no()))
                                continue;
                            for(OccupationData od:t1.getMap().get(temp_rooms.get(p).getRoom_no()))
                            {           

                                if(od.getCourse().getCourse_id()==course.getCourse_id())
                                {
                                    row_temp.createCell(p+first_col).setCellValue(od.getAllocatedStudents());
                                    row_temp.getCell(p+first_col).setCellStyle(style[batch_id-1]);
                                }
                            }

                        }
                        start++;
                }
            }

            border_last=end;//last iteration will set last end(although it sets this variable multiple times)
            }
         PropertyTemplate pt = new PropertyTemplate();
          // #1) these borders will all be medium in default color
          pt.drawBorders(new CellRangeAddress(border_first, border_last, j+1, j+8),
                  BorderStyle.MEDIUM,BorderExtent.OUTSIDE);
          if(flag==1)
          {
          pt.drawBorders(new CellRangeAddress(border_first, border_last, j, j),
                  BorderStyle.MEDIUM,BorderExtent.OUTSIDE); 
          sheet1.addMergedRegion(new CellRangeAddress(
          border_first, //first row (0-based)
          border_last, //last row  (0-based)
          j-1, //first column (0-based)
          j-1));  //last column  (0-based)
          Row temp_row=sheet1.getRow(border_first);
          if(temp_row==null)
              temp_row=sheet1.createRow(border_first);
          //temp_row.createCell(j-1,CellStyle.ALIGN_JUSTIFY, CellStyle.VERTICAL_JUSTIFY).setCellValue("Exam Day");
          TimeTable.createCell(wb, temp_row, j-1, CellStyle.ALIGN_JUSTIFY, CellStyle.VERTICAL_CENTER);
          pt.drawBorders(new CellRangeAddress(border_first, border_last, j-1, j-1),
                  BorderStyle.MEDIUM,BorderExtent.OUTSIDE);
          }
          pt.applyBorders(sheet1);
    }
     private static void createCell(Workbook wb, Row row, int column, short halign, short valign) {
            Cell cell = row.createCell(column);
            cell.setCellValue(" Exam Day ");
            CellStyle cellStyle = wb.createCellStyle();
            cellStyle.setAlignment(halign);
            cellStyle.setVerticalAlignment(valign);
            cellStyle.setRotation((short)90);
            cell.setCellStyle(cellStyle);
        }

Silex htaccess regex block all pages except one

What i'm trying to achieve:

example.com/payment - can be accessed from anywhere. While everything else can only be accessed from certain ip.

I'm using silex 2 and apache 2.4. In case you don't know, silex uses controllers and routing, so there are no direct .php files, in this case (payment.php)

here's my .htaccess file:

<IfModule mod_rewrite.c>
##Allow profiler to be accessed from office only
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteRule ^(.*)_profiler(.*)$ https://www.example.com [R=301,L]

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

RewriteRule .* - [E=ENVIRONMENT:prod]

RewriteCond %{SERVER_NAME} ^stage.
RewriteRule .* - [E=ENVIRONMENT:stage]

RewriteCond %{SERVER_NAME} .dev$ [OR]
RewriteRule .* - [E=ENVIRONMENT:dev]

### PROD ###
##force www and https
RewriteCond %{ENV:ENVIRONMENT} prod
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

### STAGE ###
##force https
RewriteCond %{ENV:ENVIRONMENT} stage
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^stage\.example\.com$ [NC]
RewriteRule ^(.*)$ https://stage.example.com/$1 [L,R=301]
##deny access
RewriteCond %{ENV:ENVIRONMENT} stage
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteRule ^((?!payment).)*$ https://stage.example.com [R=403,L]

### DEV ###
</IfModule>

The important part is the last few lines with ##deny access for stage.

I've been pulling my hair out for the past few hours and i can't seem to get this to work. I would really appreciate if someone could help me out here.

Have a nice day ! :)

Apache mod_rewrite and hide source file simultaneously

I have a local .htaccess file on a shared hosting service that contains an individual rewrite rule to map /services to the file services.html within the document root.

RewriteEngine On
RewriteBase /
RewriteRule ^services$ services.html [L]

How can I prevent consumers accessing /services.html directly (if they sniffed around for it) and have them receive a 404 HTTP response instead? I do not want any consumer knowing I have a services.html file at all, and that includes sending 302 responses that would tie back to the original /services resource.

However, I tried setting up a rule to return a 404 for /services.html but this resulted in /services also returning the 404 too.

In summary, I want consumers to only be able to see /services endpoint (200 OK) and never know what is mapped behind it, or bypass the publicly chosen endpoint (services.html return 404 Not Found).

apache2 won’t start cause ssl : "Failed to configure encrypted (?) private key"

I just created a ssl certificate shown here : http://www.tecchannel.de/a/owncloud-9-unter-ubuntu-server-16-04-lts-installieren,3277807,2

now if I start apache I get no error but with service apache2 status I get a error , error log :

[Fri Mar 31 14:55:59.639400 2017] [ssl:error] [pid 21071] AH02579: Init: Private key not found
[Fri Mar 31 14:55:59.639479 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Fri Mar 31 14:55:59.639494 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error
[Fri Mar 31 14:55:59.639504 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Fri Mar 31 14:55:59.639515 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error (Type=RSA)
[Fri Mar 31 14:55:59.639526 2017] [ssl:error] [pid 21071] SSL Library Error: error:04093004:rsa routines:OLD_RSA_PRIV_DECODE:RSA lib
[Fri Mar 31 14:55:59.639536 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Fri Mar 31 14:55:59.639547 2017] [ssl:error] [pid 21071] SSL Library Error: error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error (Type=PKCS8_PRIV_KEY_INFO)
[Fri Mar 31 14:55:59.639553 2017] [ssl:emerg] [pid 21071] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/error.log for more information
[Fri Mar 31 14:55:59.639558 2017] [ssl:emerg] [pid 21071] AH02564: Failed to configure encrypted (?) private key localhost:443:0, check /etc/apache2/ssl/apache.crt
AH00016: Configuration Failed

but whats wrong ? the file in /etc/apache2/ssl/apache.crt exists of course ... and why "Private key not found" ? apache.key exists too.

any help ? :(