0

I've installed tomcat for one website and apache2 for another (wordpress). The problem happens with wordpress website. There is nginx for reverse proxy and here it is:

server {
        listen   80;

        root /var/www/html/;
        index index.php index.html index.htm;

        server_name test.example.com;

        location / {
          try_files $uri $uri/ /index.php;
        }

        location ~ \.php$ {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8081;

         }

         location ~ /\.ht {
                deny all;
        }
}
server {
  listen 80;
  server_name conf.example.com;
  location / {
    proxy_pass http://127.0.0.1:8080;
  }
}

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name batterykazakhstan.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

}

So tomcat works well. But Wordpress is always redirecting to the welcome page in the loop. Could you help with this problem? I read about it and tried the solution suggested by putting to functions.php at top the:

remove_filter('template_redirect', 'redirect_canonical');

But that didnt help..

EDIT1:

The port 8081 is going to tomcat server and opening the test.example.com which is the Wordpress site

The port 8080 going to conf.example.com and opening the tomcat server website which works ok.

EDIT 2: here is the apache config:

ServerAdmin webmaster@localhost DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

EDIT 3:

I've got only two .htaccess files located here:

/var/www/html/wp-content/uploads/wp-clone/.htaccess

with contents:

<Files>
        Order allow,deny
        Deny from all
        Satisfy all
</Files>

And one more here

/var/www/html/wp-content/plugins/akismet/.htaccess

With contents:

<IfModule !mod_authz_core.c>
        Order Deny,Allow
        Deny from all
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
        Require all denied
</IfModule>

# Akismet CSS and JS
<FilesMatch "^(form\.js|akismet\.js|akismet\.css)$">
        <IfModule !mod_authz_core.c>
                Allow from all
        </IfModule>

        <IfModule mod_authz_core.c>
                Require all granted
        </IfModule>
</FilesMatch>

# Akismet images
<FilesMatch "^logo-full-2x\.png$">
        <IfModule !mod_authz_core.c>
                Allow from all
        </IfModule>

        <IfModule mod_authz_core.c>
                Require all granted
        </IfModule>
</FilesMatch>

EDIT 4:

wp-admin is working fine, its only the website itself. The Wordpress Adress (URL) and Site address (URL) both set to the http://test.example.com

  • Please give us more information like what service is port 8080 and 8081 is listening. What is your expected result, e.g. test.example.com should be redirected to backend tomcat, etc. – Simon MC. Cheng Aug 16 '16 at 6:54
  • @SimonMC.Cheng I've just updated the question, please take a look – maximus Aug 16 '16 at 7:08
  • Thanks for the update, so your Tomcat server has opened two ports: 8080 and 8081? Just curious, I am wondering if you have opened port 8080 under Apache which enable PHP? – Simon MC. Cheng Aug 16 '16 at 7:13
  • Tomcat opened on 8080 . Not 8081. Will check though. And 8080 is apache2 yeah opened in ports.conf . – maximus Aug 16 '16 at 7:15
  • Please help to check, Apache and Tomcat cannot both listen to port 8080. Besides, can you update the question by posting the .htaccess file of your Wordpress? It should be located in the root folder of your WordPress, example content here – Simon MC. Cheng Aug 16 '16 at 7:38
1

Let me summarize the solution here.

In this sample, our author is going to build a typical Nginx-Apache web infrastructure. Nginx will be used as a web proxy, redirecting the traffic to different back-end server. Here is a simple network diagram showing the relationship.

Network diagram

The author would like to redirect all PHP traffic to his back-end Apache web server but since we might have parameters behind the php extension, so a matching for ending in php will fail. There is the location block we have used instead:

location ~ \.php

This will match any URL with .php keyword which should be able for the author to execute backend PHP application (e.g. WordPress). For a fresh installation, we might also need to check if the .htaccess file is located at the root folder of WordPress.

Reference link: Nginx Reverse Proxy admin guide, WordPress htaccess file, htaccess WordPress Security

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.