CentOS下Nginx 配置多站点vhost
假设你想在Linux Nginx中用不同的域名访问不同的目录,这时就要配置多个vhost,具体配置如下,假设网站根目录设定在/var/www/
1、在/var/www/下新建两个目录
/var/www/ushark.net /var/www/ushark.wang
2、编辑/etc/nginx/nginx.conf
http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; #主要是加入此行,如有则忽略 }
3、在/etc/nginx/conf.d下新建两个conf文件,
/etc/nginx/conf.d/ushark.net.conf /etc/nginx/conf.d/ushark.wang.conf
4、复制如下配置信息到两个文件中,只要修改红色部分内容 !!! server_name与root保持一致即目录和域名一一对应 !!!
server { listen 80; server_name www.ushark.net; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; root /var/www/ushark.net/; if (!-e $request_filename){ # rewrite可根据网站需要增删 rewrite ^/(.*) /index.php last; } location / { index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/ushark.net/; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
5、重启Nginx
systemctl restart nginx
6、 编辑/etc/hosts !!! 核心步骤 !!!
[root@bogon ~]# vi 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 127.0.0.1 www.ushark.net 127.0.0.1 www.ushark.wang
7、设置成功

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Centos6.5安装dnsmasq
1、使用yum install dnsmasq -y安装dns(含dns server和dns代理功能) 2、查询dnsmasq已经安装成功 [root@localhost ~]#rpm -q dnsmasq dnsmasq-2.48-18.el6_9.x86_64 [root@localhost ~]# 3、配置/etc/dnsmasq.conf文件 对于/etc/dnsmasq.conf文件的行太多的话,我们只需要添加我们需要的行,先把所有行都注释掉,然后echo追加进去我们所需要的行。 3.1、修改/etc/dnsmasq.conf的快速方法:在每行的头添加字符,比如"#",注释掉文件的所有行,命令如下: sed -i 's/^/#&/g' /etc/dnsmasq.conf //注释掉/etc/dnsmasq.conf文件中的所有的行 cat /etc/dnsmasq.conf |grep -v "#"//查看注释是否OK 3.2、然后把需要的行echo追加进去 echo resolv-file=/etc/resolv.dnsmasq.conf>>/etc/...
- 下一篇
CentOS环境下为VirtualBox安装增强功能
VirtualBox安装CentOS后,再安装增强功能就可以共享文件夹、粘贴板以及鼠标无缝移动,主要步骤如下: 1、yum -y update 2、yum -y install g++gcc gcc-c++ make kernel-* #主要是在安装增强工具提示没有安装这些软件 3、yum -y install bzip2* # 增强工具用的是bzip2压缩 4、重启虚拟机 [root@localhost ~] reboot 5、点击 VirtualBox菜单栏中的【设备】->【分配光驱】->【选择虚拟盘】->【定位到 VirtualBox安装目录】->【选择 VBoxGuestAdditions.iso】,这时可能会提示一些信息,不用理会,点击【强制释放】,不要点击【取消】 6、挂载光驱到 tmp 目录 !!!核心步骤!!! 6.1)[root@localhost ~]mount /dev/cdrom /tmp/#这时会提示目录挂载成功且为ready-only 6.2)[root@localhost ~] cp -r...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8安装Docker,最新的服务器搭配容器使用
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7设置SWAP分区,小内存服务器的救世主
- 设置Eclipse缩进为4个空格,增强代码规范
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2全家桶,快速入门学习开发网站教程