Nginx相关应用
Posted 噫噫噫呀呀呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx相关应用相关的知识,希望对你有一定的参考价值。
目录
一、基于域名的 nginx 虚拟主机
1、为虚拟主机提供域名解析
echo "192.168.110.20 www.yue.com www.accp.com" >> /etc/hosts
2、为虚拟主机准备网页文档
mkdir -p /var/www/html/yue
mkdir -p /var/www/html/accp
echo "<h1>www.yue.com</h1>" > /var/www/html/yue/index.html
echo "<h1>www.accp.com</h1>" > /var/www/html/accp/index.html
3、修改Nginx的配置文件
vim /usr/local/nginx/conf/nginx.conf
......
http {
......
server {
listen 80;
server_name www.yue.com; #设置域名www.yue.com
charset utf-8;
access_log logs/www.yue.access.log;
location / {
root /var/www/html/yue; #设置www.yue.com 的工作目录
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
server {
listen 80;
server_name www.accp.com; #设置域名www.accp.com
charset utf-8;
access_log logs/www.accp.access.log;
location / {
root /var/www/html/accp;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
}
4、重启服务,访问测试
systemctl restart nginx
二、基于IP 的 Nginx 虚拟主机
ifconfig ens33:0 192.168.110.11 netmask 255.255.255.0
vim /usr/local/nginx/conf/nginx.conf
......
http {
......
server {
listen 192.168.110.10:80; #设置监听地址
server_name www.yue.com;
charset utf-8;
access_log logs/www.yue.access.log;
location / {
root /var/www/html/kgc;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
server {
listen 192.168.110.11:80; #设置监听地址
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.access.log;
location / {
root /var/www/html/accp;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
}
systemctl restart nginx
三、基于端口的 Nginx 虚拟主机
vim /usr/local/nginx/conf/nginx.conf
......
http {
......
server {
listen 192.168.110.10:8080; #设置监听 8080 端口
server_name www.yue.com;
charset utf-8;
access_log logs/www.yue.access.log;
location / {
root /var/www/html/yue;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
server {
listen 192.168.110.10:8888; #设置监听 8888 端口
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.access.log;
location / {
root /var/www/html/accp;
index index.html index.php;
}
error_page 500 502 503 504 /50x.html;
location = 50x.html{
root html;
}
}
systemctl restart nginx
以上是关于Nginx相关应用的主要内容,如果未能解决你的问题,请参考以下文章