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

nginx server configuration multiple domain names

WBOY
Release: 2016-08-30 09:21:15
Original
1433 people have browsed it

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

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template