skip to Main Content

I’m learning NGINX and I need to set a frontend webserver with NGINX and a backend webserver with Apache using .htaccess

This is the content of /etc/nginx/sites-available/my_test5.loc

server {
  charset utf-8;
  client_max_body_size 128M;

  listen 80;

  server_name my_test5.loc;
  root        /var/www/my_test5.loc/web;
  #root /var/www/my_test5.loc;
  index       index.php;


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

  # deny accessing php files for the /assets directory
  location ~ ^/assets/.*.php$ {
    deny all;
  }

  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:8080;
  }

  location ~* /. {
    #  deny all;
    allow all;
  }
}

This is the content of /etc/apache2/sites-available/my_test5.loc.conf

<VirtualHost *:8080>
  <Directory /var/www/my_test5.loc/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All 
    Order allow,deny
    allow from all 
  </Directory>
  ServerAdmin admin@my_test5.loc
  ServerName my_test5.loc
  ServerAlias www.my_test5.loc
  DocumentRoot /var/www/my_test5.loc/web/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now all I have working is the main page. If I try to navigate to site/about for example I can’t. What have I done wrong and how to use these 2 web servers?

2

Answers


  1. Chosen as BEST ANSWER

    For Nginx work

    1. use .htaccess for apache
    2. siteName.conf apache must be
    3. siteName conf must be in nginx sites-available and sites-enable
    4. be sure that you send request from 80 port to 8080(as in my case) and Apache are listening it

  2. I think your setup is only pointing correctly into index.php because of your location / {} directive, try editing your to be more permissive about your Apache access changing this block to pass through it and adding specific block to other kind of files, like assets.

    location / {
      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:8080;
    }
    
    location ~* .(jpg|jpeg|png|gif|ico|css|js|ttf|ttc|otf|eot|woff|woff2)$ {
      try_files $uri $uri/
    }
    

    This way NGINX serves your static files and Apache serves everything else.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search