Configuring apache as reverse proxy for varnish server without using Hitch on ubuntu 22.04

I am trying to varnish cache 7 with apache2 on server. Though setting up http request works just fine. but varnish can’t handle https directly so i tried Apache and Hitch but didn’t worked form. Now if any one can help me find a working configuration for varnish and Apache only.
my other question here is do i have to use two virtual hosts?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apache HTTP Host 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


<VirtualHost *:8080>
    ServerName mycloud.com
    #ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mycloud.com

    <Directory var/www/mycloud.com>
                Options Indexes FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>
    
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined    
    

</VirtualHost>


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apache HTTPS Host 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerName mycloud.com
    
    DocumentRoot /var/www/mycloud.com
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/mycloud.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mycloud.com/privkey.pem
    
    # Set up proxy headers
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyAddHeaders On
    
    SSLProxyEngine On
    SSLProxyCheckPeerCN on
    SSLProxyCheckPeerExpire on
   
     # Add headers to prevent redirect loops
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"
   
    # Optional: Log forwarding headers for debugging
    LogLevel debug
    Header add X-Forwarded-Proto "https" env=HTTPS
    Header add X-Forwarded-Port "443" env=HTTPS
    
    ProxyPass /test http://127.0.0.1:80
    ProxyPassReverse /test http://127.0.0.1:80
      

</VirtualHost>
</IfModule>


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Varnish VLC
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

vcl 4.0;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    if (req.http.X-Forwarded-Proto ~ "https") {
        set req.http.X-Forwarded-Proto = "https";
    }
}

sub vcl_backend_response {
    set beresp.http.X-Varnish = bereq.http.X-Varnish;
}

sub vcl_deliver {
    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
        set resp.http.X-Cache-Hits = obj.hits;
    } else {
        set resp.http.X-Cache = "MISS";
    }
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Varnish Service 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
Documentation=https://www.varnish-cache.org/docs/ man:varnishd

[Service]
Type=simple

# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072

# Locked shared memory - should suffice to lock the shared memory log
# (varnishd -l argument)
# Default log size is 80MB vsl + 1M vsm + header -> 82MB
# unit is bytes
LimitMEMLOCK=85983232
ExecStart=/usr/sbin/varnishd 
          -j unix,user=vcache 
          -F 
          -a :80 
          -a localhost:6092,PROXY 
          -p feature=+http2 
          -f /etc/varnish/default.vcl 
          -s malloc,256m

ExecReload=/usr/share/varnish/varnishreload
ProtectSystem=full
ProtectHome=true
PrivateTmp=true
PrivateDevices=true

[Install]
WantedBy=multi-user.target

i tried with Hitch for TLS termination but the configuration is too complex for me. so it didn’t work out.

New contributor

Muhammad Aslam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật