首页 / NGINX / 使用nginx创建虚拟主机
使用nginx创建虚拟主机
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用nginx创建虚拟主机,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1649字,纯文字阅读大概需要3分钟。
内容图文
我使用nginx的虚拟主机有问题
无论我做什么,我都会访问www / html而不是www / example1文件夹.
任何人都可以发现问题吗?
我错过了什么吗?
pi@homeserver:/etc/nginx/sites-enabled $ls -l
total 4
-rw-r--r-- 1 root root 467 Sep 4 19:41 default
lrwxrwxrwx 1 root root 38 Sep 4 19:43 example1 -> /etc/nginx/sites-available/example1
默认文件是
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location ~\.php${
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;
}
}
example1文件是
server {
listen example1.com:80;
root /var/www/example1.com;
index index.php index.html index.htm;
server_name example1.com www.example1.com;
location / {
try_files $uri $uri/ =404;
}
location ~\.php${
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;
}
}
我在日志中收到此错误
2016/09/04 21:41:08 [emerg] 1788#0: invalid host in "http://www.example1.com:80" of the "listen" directive in /etc/nginx/sites-enabled/example1.com:2
解决方法:
从错误消息来看,似乎nginx难以解析语句listen example1.com:80;到IP地址.
如果您拥有多宿主服务器并希望将服务限制到一个接口,则为listen指令提供IP地址非常有用.
在大多数情况下,声明听80;就足够了.我建议您对两个服务器块使用以下内容:
server {
listen 80;
...
}
有关更多信息,请参见this document
内容总结
以上是互联网集市为您收集整理的使用nginx创建虚拟主机全部内容,希望文章能够帮你解决使用nginx创建虚拟主机所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。