Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize the coexistence of Nginx and Apache under Linux Server

Shulou Source: shulou.com Published: 2022-06-01 18:12:18 10月03日 Update

This article mainly shows you "how to achieve the coexistence of Nginx and Apache under the Linux server", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn how to achieve the coexistence of Nginx and Apache under the Linux server "this article.

Two programs cannot listen on the same port at the same time. So find another way to solve the problem that some websites run under nginx and some websites coexist under Apache under the same server.

The solution is as follows:

Use nginx as a proxy server and web server, nginx listens on port 80, Apache listens on ports other than 80, and I temporarily use port 8080.

Solution:

Once the environment of Linux is set up, Nginx and Apache are installed successively because the default port is: 80

The server port requested by the general customer defaults to 80, so Nginx is set as the static page port: 80 position Apache sets the port to: 8080 (modify Listen:8080 in the httpd.conf file)

Websites 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

ServerName www.one.ityangs.cnServerAlias www.one.ityangs.cn one.ityangs.cnDocumentRoot / www/oneDirectoryIndex index.php index.htmlOptions + Includes + FollowSymLinks-IndexesAllowOverride AllOrder Deny,AllowAllow from All

Websites 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 www/two; location 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;}} these are all the contents of this article entitled "how to achieve the coexistence of Nginx and Apache under Linux Server". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Port server service website content article monitor train of thought learning help run two successively at the same time customer file solution easy to understand more organized Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Xiaomi Shulou Technology Shulou Information