Migrate rules from apache to nginx - nginx

I have to migrate an Apache configuration file to Nginx but as I have no experience in Nginx I would like some help.
This is my apache setup:
000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
<Directory /var/www/ff>
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www
RedirectMatch ^/$ /ff/
Alias "/uploads" "/var/www/ff/uploads/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I’m a little lost as using the parameter RedirectMatch in nginx, I guess it has another name
help me create a configuration file for nginx?
Regards,

Related

WAMP - vhost address forced to HTTPS instead of just HTTP

I have installed wamp64. configured various vhosts which work well except for one address which the system forces to go to HTTPS instead of HTTP like the rest of them. dev.test.com is forced to go to HTTPS://dev.test.com instead of HTTP://dev.test.com and of course the file is not found.
dev.test2.com goes to HTTP,
example goes to HTTP
I had a XAMPP install that had a vhosts file which had a redirect for dev.test.com to HTTPS. Thinking this might somehow interfere, I renamed that XAMPP vhost file, but I still get the same problem even after a computer reboot.
In wamp64 I am able to create any other vhost and have it work fine, but not this one. What could be causing this?
wamp64, version 3.2.9, php 7.4, apache 2.4.51
WAMP VHOST FILE:
<VirtualHost *:80>
ServerName example
DocumentRoot "c:/wamp64/www/example"
<Directory "c:/wamp64/www/example/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#
<VirtualHost *:80>
ServerName dev.test.com
DocumentRoot "c:/wamp64/www/dev.test.com"
<Directory "c:/wamp64/www/dev.test.com/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#
<VirtualHost *:80>
ServerName dev.test2.com
DocumentRoot "c:/wamp64/www/dev.test2.com"
<Directory "c:/wamp64/www/dev.test2.com/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#
My previous XAMPP VHOST FILE - NOW RENAMED TO DISABLE IT (httpd-vhosts_old.conf)
<VirtualHost dev.test.com:80>
ServerName dev.test.com
DocumentRoot "C:\xampp\htdocs\dev.test.com"
<Directory "C:\xampp\htdocs\dev.test.com">
Options All
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/dev.test.com-error.log"
CustomLog "dev.test.com-access.log" combined
#redirect non SSL URI to SSL URI
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.dev.test.com [OR]
RewriteCond %{SERVER_NAME} =dev.test.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I ended up configuring a local SSL certificate for the server and converted all local hostnames to access SSL which worked fine. I know this does not answer the posted question, but at least allowed me to proceed.

How to resolve 403 Forbidden on Symfony website

I just started a project and when I try to access the website I get this error:
Forbidden
You don't have permission to access this resource.
Here's the config of my website:
<VirtualHost *:80>
ServerName portfolio.lxc
ServerAdmin webmaster#localhost
DocumentRoot /var/www/portfolio/public
<Directory /var/www/portfolio/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I enabled my website like this
a2ensite portfolio
systemctl reload apache2
And then this error. When I looked on the Internet, it was said to allow "Options FollowSymLinks" but it's already allowed on my conf. I tried
chmod -R 777 /var/www/portfolio/
But I still get this error.

ProxyPass rule for Wordpress Site with Apache2

I have a wordpress site running on wordpress.myorg.com. For authentication I have to redirect it my internal server running CAS server.
Internal Server does not have DNS name. So, I’m using local DNS with IP address in HOST file to redirect to CAS server. All the things working correctly such a way.
Now I wanted to add ProxyPass rules, so that the User only sees wordpress.myorg.com all the time.
After adding ProxyPass rules, when I hit wordpress.myorg.com/wp-login.php it returns page with 500 internal error rather then showing CAS login screen.
Here is the Virtual Host entry I have done in Apache web server for Wordpress Site
<VirtualHost *:80>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
DocumentRoot /var/www/html/wordpress
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTPS} !=on
RewriteRule ^/?CAS/(.*) https://wordpress.myorg.com/CAS/$1 [R,NE,L]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/myorg.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/myorg.com.key
ProxyRequests On
ProxyVia On
ProxyPass /CAS/ ajp://cas.myorg.com:8009/CAS/
ProxyPassReverse /CAS/ ajp://cas.myorg.com:8009/CAS/
</VirtualHost>
Any help on this would be appreciable.
Thanks.
Got the issue. I forgot to enable SSLProxyEngine. Just enabled it and its working like a charm.
Edit for HTTPs portion.
<VirtualHost *:443>
ServerAdmin your_email_address
ServerName wordpress.myorg.com
ServerAlias wordpress.myorg.com
SSLEngine on
## Added these lines ##
SSLProxyEngine On
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
## -- ##
SSLCertificateFile /etc/apache2/ssl/myorg.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/myorg.com.key
ProxyRequests On
ProxyVia On
ProxyPass /CAS/ ajp://cas.myorg.com:8009/CAS/
ProxyPassReverse /CAS/ ajp://cas.myorg.com:8009/CAS/
</VirtualHost>

Configuring .htaccess for multiple wordpress sites

I have multiple wordpress installs that I need to access with multiple domains and I need a way to accomplish this. I have devised a folder structure that I think will be the best way, but I need help with the .htaccess. For simplicity sake, let's say I have two wordpress sites. Fully separate.
www.b.campscoreboard.net is in the folder
/a/b
www.c.campscoreboard.net is in the folder
/a/c
www.campscoreboard.net is pointing to
/a
The a folder contains nothing except an .htaccess file to help me route the domains properly. That's where I need help. I would like to point www.campscoreboard.net to that root /a folder. In my perfect world, the following things would work.
The "b" site would work just fine using www.b.campscoreboard.net or campscoreboard.net/b
The "c" site would work just fine using www.c.campscoreboard.net or www.campscoreboard.net/c
I need "b" and "c" to have their built in permalinks functions to still work. In other words, if I type www.c.campscoreboard.net/forums, I need that to work. I don't want to have to go all the way back to www..campscoreboard.net/c/forums for my links to work (which is what it's currently doing).
What needs to be in that .htaccess file in the /afolder to properly route these domains?
Update 1: Rather than breaking real sites trying this stuff, I just made 2 wordpress installs in the directory tree above. Sorry about the www's. That's what worked for testing purposes.
Here's what happened:
After installing the sites, they worked as expected. I could load the two wordpress sites with either b.campscoreboard.net or campscoreboard.net/b.
However, I got an internal server error on all campscoreboard.net, b.campscoreboard.net, and c.campscoreboard.net after adding the suggested .htaccess of...
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName b.campscoreboard.net
ServerAlias www.b.campscoreboard.net
DocumentRoot /a/b
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName c.campscoreboard.net
ServerAlias www.c.campscoreboard.net
DocumentRoot /a/c
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What do you think I'm doing wrong?
Follow these steps:
a) Create Apache virtualhost:
Read this tutorial.
Example configuration:
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName mudministry.com
ServerAlias www.mudministry.com
DocumentRoot /mudmin/home
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName userspice.com
ServerAlias www.userspice.com
DocumentRoot /mudmin/userspice
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
b) Add wordpress files in /mudmin/home and /mudmin/userspice. Make sure you access these sites first time using the servernames specified above. mudministry.com and userspice.com
This will make sure the your wordpress urls are generated correctly.
c) Use Reverse proxy for mudministry.org
Read this tutorial:
Example configuration:
<VirtualHost 10.10.1.91:80>
ServerName mudministry.org
ServerAdmin webmaster#localhost
## You dont have to keep this /mudministry
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyAddHeaders Off
ProxyPass /home http://mudministry.com
ProxyPassReverse /home http://mudministry.com
ProxyPass /userspice http://userspice.com
ProxyPassReverse /userspice http://userspice.com
</VirtualHost>

Why does localhost work but my alias does not?

I currently have this apache2 site configuration:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName engine.com
ServerAlias www.engine.com
DocumentRoot /var/www/engine.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I type engine.com I just get a blank page.
My directory setup is like this
/var/www/engine.com/public_html/wp-content...
Localhost works fine and wordpress installation is triggered, but as I say engine.com just brings me a blank page.
Don't you need to add
engine.com 127.0.0.1
to your hosts file?

Resources