在Ubuntu的nginx中建立多个虚拟主机方法
浏览数 197340
赞
(0)
一、在/data/www/中增加一个目录www.wjw.com,及子目录pulic,里面放一个index.php文件作为访问首页
二、在/etc/nginx/sites-available/中新增一个配置文件www.wjw.com,文件内容如下:
server {
listen 80;
root /data/www/www.wjw.com/public;
index index.php;
server_name www.wjw.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
#root /data/www/www.wjw.com/public;
#index index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
三、创建软链接:
ln -s /etc/nginx/sites-available/www.wjw.com /etc/nginx/sites-enabled/www.wjw.com
sites-available 目录中的配置文件是已启用与未启用的都可以存放在里面
sites-enabled 目录中的配置文件是当前正在使用的
四、重启nginx:
service nginx restart
五、在你的本机配置hosts,使www.wjw.com访问到服务器的IP上。
二、在/etc/nginx/sites-available/中新增一个配置文件www.wjw.com,文件内容如下:
server {
listen 80;
root /data/www/www.wjw.com/public;
index index.php;
server_name www.wjw.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
#root /data/www/www.wjw.com/public;
#index index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
三、创建软链接:
ln -s /etc/nginx/sites-available/www.wjw.com /etc/nginx/sites-enabled/www.wjw.com
sites-available 目录中的配置文件是已启用与未启用的都可以存放在里面
sites-enabled 目录中的配置文件是当前正在使用的
四、重启nginx:
service nginx restart
五、在你的本机配置hosts,使www.wjw.com访问到服务器的IP上。