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
成功
二、nginx基于域名的多站点配置
只需要改这两个即可,别的不需要动,端口默认的都是80