Nginx配置多站点

准备工作,在C:\Windows\System32\drivers\etc\hosts文件中添加以下两个测试:
#服务器IP        域名
192.168.1.169 www.lrfun.com
192.168.1.169 www.lrfun2.com

方法一:
1.打开配置文件:/etc/nginx/nginx.conf,将server{...}复制粘贴到下面,修改相关的域名和目录
2.重启nginx:service nginx restart
3.打开浏览器访问域名

方法二:

1.在/etc/nginx/目录下,新建lrfun2.conf(名字最好命名为域名,如域名www.lrfun2.com,则命名为lrfun2.conf,方便查找),文件内容为:

server{       
	listen 80;
	server_name lrfun2.com www.lrfun2.com;
	root /var/www/lrfun2;
	index index.html index.htm;
	charset utf-8;
	location / {
		root /var/www/lrfun2;
		index index.html index.php index.htm;
	}
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}
	location ~* \.(jpg|gif|png)$ {
		if (-f $request_filename) {
			expires max;
			break;
		}
	}
	location ~ /\.ht {
		deny all;
	}
}
2.修改/etc/nginx/nginx.conf文件,在http{...}中添加:include /etc/nginx/lrfun2.conf;
3.重启nginx:service nginx restart

4.打开浏览器访问域名


欢迎转载,原文地址:http://www.lrfun.com/html/technology/linux/2017/0615/116.html

上一篇:Ubuntu 配置LNMP环境
下一篇:Linux下MySQL误操作(UPDATE、DELETE等操作没加WHERE条件)导致数据丢失,如何恢复?