Nginx 配置多站点vhost 的方法介绍

这篇文章主要介绍了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 - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “KaTeX parse error: Double superscript at position 12: request" ' '̲status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer” ’ ‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""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 KaTeX parse error: Expected 'EOF', got '#' at position 128: …l index.htm; } #̲error_page 404 … { # 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 d o c u m e n t r o o t document_root documentrootfastcgi_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; #}}IIS7-VPS大全
5、重启Nginx

systemctl restart nginx
6、 编辑/etc/hosts  !!! 核心步骤 !!!

[root@bogon ~]# vi 127.0.0.1 localhost.localdomain localhost::1 localhost6.localdomain6 localhost6127.0.0.1 www.ushark.net127.0.0.1 www.ushark.wang
总结

以上所述是小编给大家介绍的Nginx 配置多站点vhost 的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值