search
Homephp教程php手册nginx server configuration multiple domain names

nginx server supports configuring multiple sites. We can configure subdomain names to place multiple projects under one domain name.

So how to implement this process?

There are many solutions on the Internet, some are too complicated to write, and some are configured incorrectly. In other words, some configuration items need to be configured according to the actual environment of the host.

1. Assume that your project path is placed under the /home/wwwroot/ path, and the installation path of nginx is under the /usr/local/nginx/ directory

2. After nginx is installed, there will be a default configuration file. The file path is /usr/local/nginx/conf/nginx.conf

3. Now you need to map your project to multiple domain names. First check the last line of the nginx.conf file, which indicates that all .conf files in the current vhost directory are included. At this point, if there is no vhost file we can create this folder.

<span>                access_log  /home/wwwlogs/<span>access.log  access;
        }
include vhost/*.conf;</span></span>

4. Then create a new domain name configuration file you need to add in the vhost directory and name it custom. Then we can add content to it. Several specific configuration items can be explained below (simply skipped).

1.index index.html  index.php 表示默认的定位的文件,假如直接访问域名,会定位到index.html或者index.php文件<br>2.fastcgi_pass  这个命令是指定将http代理到哪个fastcgi服务端接口<br>3.fastcgi_index  该指令设置的文件会被附加到URI的后面并保存在变量$fastcgi_script_name中<br>4.fastcgi_param SCRIPT_FILENAME   脚本文件请求的路径 <br>5.include  fastcgi_params;  包含fastcgi_params中的所有参数
<span>server{
        listen 80<span>;
        server_name www.news.com;
        root /home/wwwroot/news/<span>;
        location /<span>{
                index index.html  index.php;
<span>        }
        location ~<span> \.php$ {
            fastcgi_pass   127.0.0.1:9000<span>;<br>        #fastcgi_pass   unix:/tmp/fastcgi.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;
            include    <span>fastcgi_params;

        }
}</span></span></span></span></span></span></span></span>

5. If we are testing on this machine, after setting up the virtual domain name, how can we access it on our own Linux host?

1. We can map the domain name to our own host by modifying /etc/hosts. For example, www.news.com that I defined before

2. We open the hosts file and add 127.0.0.1 www.news.com

at the end

3. If you modify the hosts file and still cannot access it. That means you still need to modify the network file. Open the /etc/sysconfig/network file, change it to NETWORKING=yes, then service network restart, restart the network

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),