不言不语

您现在的位置是: 首页 >  Linux

Linux

linux之nginx多站点配置

2022-03-17Linux
linux之nginx多站点配置,基于多端口和多域名的相关详细配置。

一、nginx基于端口的多站点配置


[root@localhost nginx]# cd conf


[root@localhost conf]# vi nginx.conf


worker_processes  1;

events {

    worker_connections  1024;

}


http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    include vhost/shop.conf;

    include vhost/blog.conf;

}




[root@localhost conf]# mkdir vhost


新建文件


-rw-r--r--. 1 root root 290 Mar 17 07:22 blog.conf

-rw-r--r--. 1 root root 290 Mar 17 07:18 shop.conf


配置文件


server {

        listen       81;

        server_name  localhost;

        location / {

            root   /home/shop;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }


重启nginx


[root@localhost conf]#  /usr/local/nginx/sbin/nginx -s reload


如果报错


nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)


解决方法:使用nginx -c的参数指定nginx.conf文件的位置


查看端口[root@localhost conf]# netstat -ntlp


image.png

image.png

成功


二、nginx基于域名的多站点配置



image.png


只需要改这两个即可,别的不需要动,端口默认的都是80


文章评论