Analysis of the implementation method of Nginx and Apache coexistence under Linux server

Analysis of the implementation method of Nginx and Apache coexistence under Linux server

This article describes how to implement coexistence of Nginx and Apache on Linux server. Share with you for your reference, the details are as follows:

There cannot be two programs listening on the same port at the same time. So we changed our thinking and solved the problem of some websites running under nginx and some websites running under Apache coexisting on the same server.

Solution:

Use nginx as a proxy server and web server. nginx listens to port 80, and Apache listens to ports other than 80. I will use port 8080 for now.

Solution:

  • Once the Linux environment was set up, Nginx and Apache were installed one after another. Since the default ports are: 80
  • The default server port for general client requests is 80, so Nginx is set as static page port: 80; Apache is set to port: 8080 (modify Listen: 8080 in the httpd.conf file)

Website under Apache:

Add in nginx.conf

server {
   listen 80;
   server_name www.one.ityangs.cn one.ityangs.cn;
location / {
   proxy_pass http://127.0.0.1:8080;
   proxy_redirect off;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

Add in httpd.conf

<virtualhost *:8080>
ServerName www.one.ityangs.cn
ServerAlias ​​www.one.ityangs.cn one.ityangs.cn
DocumentRoot /www/one
DirectoryIndex index.php index.html
<Directory /www/one>
Options +Includes +FollowSymLinks -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
</virtualhost>

Website under Nginx:

Add in nginx.conf

 server {
  listen 80;
  server_name two.ityangs.cn www.two.ityangs.cn;
  root /www/two;
  location /{
   index index.html index.htm index.php;
    if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php?s=$1 last;
    break;
   }
   error_page 404 /var/www/html/404.html;
  }
  location ~ \.php(.*)$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    include fastcgi_params;
  }
}

I hope this article will help you maintain your Linux server.

You may also be interested in:
  • Steps to build a file server using Apache under Linux
  • Solve the problem of case sensitivity of Linux+Apache server URL
  • 8 Security Tips for Linux Apache Web Server Security
  • Deploy Python's Django project to Apache server under Linux
  • View Apache Server Error Log on Linux System
  • Linux installation apache server configuration process

<<:  How to make your own native JavaScript router

>>:  MySQL SQL statement analysis and query optimization detailed explanation

Recommend

Detailed explanation of the sticky position attribute in CSS

When developing mobile apps, you often encounter ...

Example code of html formatting json

Without further ado, I will post the code for you...

Solution to 404 Problem of Tomcat Installation in Docker

Find the containerID of tomcat and enter the toma...

MySQL 8.0.14 installation and configuration method graphic tutorial (general)

MySQL service 8.0.14 installation (general), for ...

Douban website's method for making small changes to website content

<br />Reading is a very important part of th...

Use non-root users to execute script operations in docker containers

After the application is containerized, when the ...

Summary of WEBAPP development skills (notes for mobile website development)

1. To develop web responsively, the page must ada...

Several ways to easily traverse object properties in JS

Table of contents 1. Self-enumerable properties 2...

How to quickly query 10 million records in Mysql

Table of contents Normal paging query How to opti...

Vue implements the right slide-out layer animation

This article example shares the specific code of ...

Detailed explanation of Nginx version smooth upgrade solution

Table of contents background: Nginx smooth upgrad...

Detailed analysis of each stage of nginx's http request processing

When writing the HTTP module of nginx, it is nece...

Using JS to implement a simple calculator

Use JS to complete a simple calculator for your r...