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

SQL query for users who have logged in for at least n consecutive days

Take 3 consecutive days as an example, using the ...

Detailed graphic tutorial on how to enable remote secure access with Docker

1. Edit the docker.service file vi /usr/lib/syste...

Specific method to add foreign key constraints in mysql

The operating environment of this tutorial: Windo...

How to install Docker using scripts under Linux Centos

What is the main function of Docker? At present, ...

Detailed explanation on how to get the IP address of a docker container

1. After entering the container cat /etc/hosts It...

Minio lightweight object storage service installation and browser usage tutorial

Table of contents Introduction Install 1. Create ...

Detailed summary of mysql sql statements to create tables

mysql create table sql statement Common SQL state...

Example of how to configure cross-domain failure repair in nginx

Nginx cross-domain configuration does not take ef...

JavaScript timer to achieve limited time flash sale function

This article shares the specific code of JavaScri...

Pure HTML and CSS to achieve JD carousel effect

The JD carousel was implemented using pure HTML a...

Vue implements click feedback instructions for water ripple effect

Table of contents Water wave effect Let's see...

Detailed explanation of the difference between run/cmd/entrypoint in docker

In Dockerfile, run, cmd, and entrypoint can all b...

Implementation of MySQL5.7 mysqldump backup and recovery

MySQL backup Cold backup:停止服務進行備份,即停止數據庫的寫入Hot ba...