[root@Nginx-server ~]# tar zxvf nginx-1.11.2.tar.gzhtml
[root@Nginx-server ~]# useradd -M -s /sbin/nologin nginx
[root@Nginx-server ~]# cd nginx-1.11.2
[root@Nginx-server nginx-1.11.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_modulenginx
[root@Nginx-server nginx-1.11.2]# make && make install web
[root@Nginx-server nginx-1.11.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@Nginx-server nginx-1.11.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@Nginx-server nginx-1.11.2]# nginxvim
[root@Nginx-server nginx-1.11.2]# cd /usr/local/nginx/conf/app
[root@Nginx-server conf]# sed -i '$i\include vhosts/*;' nginx.conf網站
[root@Nginx-server conf]## grep -vE "#|^$" /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include vhosts/*;
}spa
[root@Nginx-server conf]## mkdir /usr/local/nginx/conf/vhosts/ #創建虛擬主機的的專屬目錄vhosts;.net
[root@Nginx-server conf]# vim /usr/local/nginx/conf/vhosts/www.xiaoyu.com3d
server {
listen 80;
server_name www.xiaoyu.com;
location / {
root /usr/local/nginx/html/www.xiaoyu.com/;
index index.html index.htm;
}server
expires 3d;
}
root@Nginx-server ~]# vim /usr/local/nginx/conf/vhosts/www.hexun.net
server {
listen 80;
server_name www.hexun.net;
location / {
root /usr/local/nginx/html/www.hexun.net/;
index index.html index.htm;
}
expires 3d;
}
[root@Nginx-server ~]# mkdir /usr/local/nginx/html/wwww.xiaoyu.com -p #建立對應虛擬主機xiaoyu的網站根目錄,hexun.net亦是如此,網頁內容區分開便可
[root@Nginx-server ~]# cd /usr/local/nginx/html/wwww.xiaoyu.com/
[root@Nginx-server wwww.xiaoyu.com]# ls
[root@Nginx-server wwww.xiaoyu.com]# echo "This is xiaoyu website" > index.html
配置完成以後驗證便可