Home > Backend Development > PHP Tutorial > nginx multiple site configuration nginx apache nginx php nginx rewrite

nginx multiple site configuration nginx apache nginx php nginx rewrite

WBOY
Release: 2016-07-29 08:52:06
Original
1167 people have browsed it

Server address: 192.168.1.231

Domain name: test1.com Directory: /www/test1.com

Domain name: test2.com Directory: /www/test2.com

This configuration idea

Put 2 sitestest1.com,test2.com The directory that nginx can access /www/
Create an nginx configuration file for each site test1.com.conf, test2.com.conf, And put the configuration file in /etc/nginx/vhosts/
Then add an include sentence in /etc/nginx.conf to include all the configuration files created in step 2 (use * sign)
Restart nginx

Actual operation:

[root@localhost ~]# mkdir /www/test1.com
[root@localhost ~]# mkdir /www/test2.com
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# mkdir vhosts
[root@localhost nginx]# cd vhosts/
[root@localhost vhosts]# vi test1.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test1.com www.test1.com;
        access_log  /www/access_test1.log  main;
        location / {
            root   /www/test1.com;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
}
[root@localhost vhosts]# vi test2.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test2.com www.test2.com;

        access_log  /www/access_test2.log  main;

        location / {
            root   /www/test2.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test2.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}
Copy after login

Modify nginx.conf

Back up the configuration file


[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425
[root@localhost ~]# vi /etc/nginx/nginx.conf.
#修改成以下内容
user  nginx;
worker_processes  1;

# main server error log
error_log       /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;
events {
        worker_connections  1024;
}
# main server config
http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;
        server {
                listen         80;
                server_name     _;
                access_log      /var/log/nginx/access.log main;
                server_name_in_redirect  off;
                location / {
                        root  /usr/share/nginx/html;
                        index index.html;
                }
        }
    # 这一行是加载上面的配置文件
    include /etc/nginx/vhosts/*;
}

重起nginx服务
[root@localhost ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]# 
Copy after login

Let’s test whether it is successful

Copy the nginx default page /usr/html/index.html to /www/test1.com and /www respectively /test2.com

Then change the contents of index.html to test1.com and test2.com respectively

The test machine is windowsdowns

Modify the host file

# localhost name resolution is handled within DNS itself.

# 127.0.0.1 localhost

# ::1 localhost

192.168.1.231 www.test1.com

192.168.1.23 1 www.test2.com

Open www.test1 on the server. com

test1.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Com commercial support is available at nginx.com.

Thank you for using nginx.

Open www.test2.com

test2.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

Test successful! ! ! ! !


The above has introduced nginx multiple site configurations, including nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template