Home php教程 php手册 nginx server configuration multiple domain names

nginx server configuration multiple domain names

Aug 30, 2016 am 09:21 AM

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>
Copy after login

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中的所有参数
Copy after login
<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>
Copy after login

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 of this Website
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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24