I created an apache server on Centos and configured the entire environment. I've already done the part of pointing the IP to the domain and even activated the SSL certificate (Lets Encrypt) and it worked, but some things are going wrong. For example, when I click on any link on the screen on my domain, the URL automatically goes to my IP instead of continuing on the domain. The same happens when I try to access domain.com/wp-admin, it is redirected to IP/wp-admin. I think it's some basic configuration but I'm a beginner in this part so if anyone can help I'll be grateful!
Vhosts:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/wordpress
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/requests.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
for default conf file (redirects all request to your domain with https):
<VirtualHost IP_ADDRESS:80>
Protocols h2 h2c http/1.1
ServerAdmin mail#example.com
Redirect permanent / https://example.com/
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And for your domain conf file:
<VirtualHost example.com:80>
Protocols h2 http/1.1
RewriteEngine on
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost example.com:443>
Protocols h2 h2c http/1.1
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
ServerName example.com
DocumentRoot /var/www/example.com
Alias / "/var/www/example.com/"
<Directory /var/www/example.com/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
</VirtualHost>
Related
I've been trying to deploy a sveltekit app on my vps but it's not really working the home page is showing but when going on other url e.g http://weather.app.julesthibault.fr/test it's showing an apache error what did I do wrong ? This is the repository that I'm using : https://github.com/Julestblt/svelte-weather-app and this is my apache configuration :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName weather.app.julesthibault.fr
ServerAlias weather.app.julesthibault.fr
DocumentRoot /var/www/svelte-weather-app/build/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =julesthibault.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Website configured on my localhost 'http://subdomain.customdomain.com' is redirecting to 'https://www.subdomain.customdomain.com' and I cant figure out why.
What I have done is the following:
Setup a hostname on dyn.com ie subdomain.dyndns.org
Setup router to update the dynamic IP to subdomain.dyndns.org on dyn.com (router is updating the IP correctly)
Since I want to use a custom domain added a CNAME record for subdomain.customdomain.com pointing to subdomain.dyndns.org (this is resolving to the correct IP)
Setup port forwarding on the port 80 on my router (external 80 to internal 80)
Setup virtual host on my local apache:
<VirtualHost subdomain.customdomain.com:80>
DocumentRoot "C:/xampp/htdocs/customdomain"
ServerName subdomain.customdomain.com:80
ServerAlias subdomain.customdomain.com:80
</VirtualHost>
Now when I open http://subdomain.customdomain.com in my browser it redirects to https://www.subdomain.customdomain.com with the error: This site can’t be reached www.subdomain.customdomain.com’s server IP address could not be found.
When I directly add subdomain.customdomain.com to point to my LAN IP in my windows host file, It does not redirect and website works fine.
Just cant figure out what is going wrong?
Below are the .htaccess file contents:
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<FilesMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition attachment
</FilesMatch>
Fixed the issue! The issue was with the virtual host configurations.
The configuration which was causing the issue
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs/">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost subdomain.customdomain.com:80>
DocumentRoot "C:/xampp/htdocs/some/directory/wordpress"
ServerName subdomain.customdomain.com:80
ServerAlias subdomain.customdomain.com:80
</VirtualHost>
<VirtualHost www.somedomain.com:80>
DocumentRoot "C:/xampp/some/directory2/wordpress"
ServerName www.somedomain.com:80
ServerAlias somedomain.com:80
</VirtualHost>
The configuration which fixed it:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName subdomain.customdomain.com:80
ServerAlias subdomain.customdomain.com:80
DocumentRoot "C:/xampp/htdocs/some/directory/wordpress"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/some/directory2/wordpress"
ServerName www.somedomain.com:80
ServerAlias somedomain.com:80
</VirtualHost>
I'm running a ReactJS app at https://www.hackachieve.com with the following structure:
Port 80/443: Front-end - ReactJS SPA
Port: 8000 - Back-end - django rest framework API
I've installed wordpress properly at /var/www/html and I'm trying to redirect the user from /blog to it.
The issue is that my proxy pass is not working. What happens when the user tries to reach https://www.hackachieve.com/blog is that its redirected back to the main page /. I've found a 301 redirect by inspecting the devtools.
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName hackachieve.com
ServerAlias www.hackachieve.com
ServerAdmin joaopaulofurtado#live.com
DocumentRoot /var/www/hackachieve-frontend
ProxyPreserveHost On
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
RewriteEngine on
RewriteCond %{SERVER_NAME} =hackachieve.com [OR]
RewriteCond %{SERVER_NAME} =www.hackachieve.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerName hackachieve.com
ServerAlias www.hackachieve.com
ServerAdmin joaopaulofurtado#live.com
DocumentRoot /var/www/hackachieve-frontend
ProxyPreserveHost On
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
ErrorLog ${APACHE_LOG_DIR}/error-frontend.log
CustomLog ${APACHE_LOG_DIR}/access-frontend.log combined
RewriteEngine off
RewriteCond %{SERVER_NAME} =www.hackachieve.com [OR]
RewriteCond %{SERVER_NAME} =hackachieve.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hackachieve.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hackachieve.com/privkey.pem
</VirtualHost>
<VirtualHost *:8000>
ServerName hackachieve.com
ServerAlias www.hackachieve.com
ServerAdmin joaopaulofurtado#live.com
DocumentRoot /var/www/hackachieve-backend
ErrorLog ${APACHE_LOG_DIR}/error-backend.log
CustomLog ${APACHE_LOG_DIR}/access-backend.log combined
Alias /static /var/www/hackachieve-backend/static
<Directory /var/www/hackachieve-backend/static>
Require all granted
</Directory>
<Directory /var/www/hackachieve-backend/hackachieve>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIPassAuthorization On
WSGIDaemonProcess hackachieve python-home=/var/www/hackachieve-backend/venv python-path=/var/www/hackachieve-backend
WSGIProcessGroup hackachieve
WSGIScriptAlias / /var/www/hackachieve-backend/hackachieve/wsgi.py
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hackachieve.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hackachieve.com/privkey.pem
</VirtualHost>
I expect that when the user reaches https://www.hackachieve.com/blog he gets redirected to my Wordpress blog.
I don't want to ReactJS to handle this route
I have a service running on my server, it is possible to access it through http and ws. I have the dilemma when I am going to configure the subdomain in Apache2, because I would like to have both protocols working for the same subdomain. That is, if the incoming connection is using the HTTP protocol (http://) then Apache2 must redirect the connection to SERVICE:HTTP_PORT, if it is websocket (ws://) I want it to go to SERVICE:WS_PORT. Is there any way to do this without having to use routes like / ws or / websocket to make the connection?
Duplicate for WebSockets and Apache proxy : how to configure mod_proxy_wstunnel?
I followed the instructions of this answer: https://stackoverflow.com/a/35141086/4763630
This is the final Apache2 config for my server:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName service.example.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) wss://service.example.com/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) https://service.example.com/$1 [P,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#example.com
ServerName service.example.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:1886/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:1996/$1 [P,L]
ProxyPassReverse / https://service.example.com
<Location "/">
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</Location>
SSLEngine On
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCipherSuite HIGH:MEDIUM
SSLCertificateFile cert.pem
SSLCertificateKeyFile privkey.pem
SSLCertificateChainFile chain.pem
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now I can access with http://, https://, ws:// and wss://.
I have Bitnami LAMP stack running on AWS. I have installed Wordpress in a folder called /wordpress/ using a downloaded Bitnami installer. It is visible publicly through the url: 11.11.111.11/wordpress/. I have set up an A Record for a domain name to point to the IP address. The result is that the site now is visible through the URL: mydomain.com/wordpress/.
Problem is that I want it to be visible via the url: mydomain.com (without the /wordpress/ folder).
I have tried everything that I have found on the topic for 2 days and simply cannot solve this seemingly simple task. I'm happy to provide more info on request. Please can someone help!
EDIT
I have the following two Apache configuration files:
opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf
with content:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/server.key"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
opt/bitnami/apps/wordpress/conf/httpd-app.conf
with content:
RewriteEngine On
RewriteRule /<none> / [L,R]
<IfDefine USE_PHP_FPM>
<Proxy "unix:/opt/bitnami/php/var/run/wordpress.sock|fcgi://wordpress-fpm" timeout=300>
</Proxy>
</IfDefine>
<Directory "/opt/bitnami/apps/wordpress/htdocs">
Options +MultiViews +FollowSymLinks
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
<IfDefine USE_PHP_FPM>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://wordpress-fpm"
</FilesMatch>
</IfDefine>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [S=1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</Directory>
Include "/opt/bitnami/apps/wordpress/conf/htaccess.conf"
The result is that mydomain.com (registered at Godaddy) points to the root and not the wordpress directory.
My understanding of Apache is that vhosts allows you to point a domain to a document root folder and have multiple domains pointing to a single server IP address. So I don't see why this does not work.
I found the solution. Maybe this can help someone.
Do not use the /opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf config file, but instead use the /opt/bitnami/apps/wordpress/conf/httpd-prefix.conf and run the following command:
sudo /opt/bitnami/apps/wordpress/bnconfig --appurl /