How to configure subdomain reverse proxy  with  Apache in Redhat
https://favpng.com/

How to configure subdomain reverse proxy with Apache in Redhat

I am new in the Linux environment just why this notes I am writing for my own reference.

This article will helpful for .net core developer who are going to host his project with redhat. In this case .net project run in kestral server and when you want to map domain and subdomain with different port you need to configure reverse proxy to serve the request.

Apache is easy to learn and configure web server providing an ability to host websites mainly via HTTP or HTTPS protocols. Under RHEL 8 / CentOS 8 system Apache webserver is known under the name httpd

First access root to install apache with "su -" and enter your password

No alt text provided for this image

First step is to use dnf command to install package called httpd

# dnf install httpd        
No alt text provided for this image

Now enabled and start webserver

# systemctl enable httpd 
# systemctl start httpd
#        

You will see the following output if everything ok.

No alt text provided for this image

Create a conf file for your virtual host. By default all conf file included with your apache configuration.

cd /etc/httpd/conf.d/
touch yourapplication.conf
        

Now add your virtual host configurations for reverse proxy


[root@ip-172-31-9-33 ~]# vim /etc/httpd/conf.d/uat.conf


<VirtualHost *:80>
? ? ServerName yoursite.com
? ? ServerAlias www.yoursite.com
? ? ProxyPreserveHost On
? ? ProxyPass "/" "https://localhost:8000/"
? ? ProxyPassReverse "/" "https://localhost:8000/"
? ? ErrorLog /var/log/httpd/yoursite-error.log
? ? CustomLog /var/log/httpd/yoursite-access.log common
</VirtualHost>


<VirtualHost *:80>
? ? ServerName uat.yoursite.com
? ? ServerAlias uat.yoursite.com
? ? ProxyPreserveHost On
? ? ProxyPass "/" "https://localhost:3000/"
? ? ProxyPassReverse "/" "https://localhost:3000/"
? ? ErrorLog /var/log/httpd/uat-yoursite-error.log
? ? CustomLog /var/log/httpd/uat-yoursite-access.log common
</VirtualHost>


<VirtualHost *:80>
? ? ServerName stg.yoursite.com
? ? ServerAlias stg.yoursite.com
? ? ProxyPreserveHost On
? ? ProxyPass "/" "https://localhost:4000/"
? ? ProxyPassReverse "/" "https://localhost:4000/"
? ? ErrorLog /var/log/httpd/stg-yoursite-error.log
? ? CustomLog /var/log/httpd/stg-yoursite-access.log common
</VirtualHost>

<--Notes:Use your local machine address by replace localhost. In Aws it's not working with localhost. you should use local IP. You can see it after login with putty/>
        

Now restart your apache server to reflect the changes

systemctl restart httpd        

In Redhat or CentOS you can get following error when reverse proxy

[Tue Dec 14 05:35:04.861823 2021] [proxy_http:error] [pid 43911:tid 139812719781632] [client 116.68.207.82:60532] AH01114: HTTP: failed to make connection to backend: 0.0.0.
[Tue Dec 14 05:35:05.137142 2021] [proxy:error] [pid 43911:tid 139812896564992] (13)Permission denied: AH00957: HTTP: attempt to connect to 0.0.0.0:3000 (0.0.0.0) failed

0        

By default, SELinux prevents Apache from initiating outbound connections, so it is unable to proxy requests

So you need to run following command to allow make outbound command

/usr/sbin/setsebool -P httpd_can_network_connect 

1        

you can Check also

https://sajid-ict.medium.com/a-guide-to-asp-net-core-in-linux-7192f7ed0953

That's it happy coding

要查看或添加评论,请登录

Sajidur Rahman的更多文章

  • 1. Learning Type Script: Hello World

    1. Learning Type Script: Hello World

    Introduction: Typescripts describe the shape and behavior of your code and what value will be when we run our program…

  • Learning Objectives and Key Results (OKR)

    Learning Objectives and Key Results (OKR)

    Do you feel when you are doing something? Why are you doing and what is the result? If not you should do it. OKR is a…

社区洞察