Nginx 配置两个虚拟主机,无法访问

回复 收藏
各位好:
我在/usr/local/nginx/conf/vhosts下配置两个配置文件,分别为aaa.conf:
内容为:
server
{
listen 80;
server_name aaa.com;
index index.htm index.html index.php;
root /data/www;

location ~\.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}

}
另一个为111.conf

server
{
    listen 80;
    server_name 111.com;
    index index.html index.htm index.php;
    root /data/wordpress;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/www1.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wordpress$fastcgi_script_name;
    }

}

并且我在php-fpm.conf中规定了两个pool,配置如下:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/www.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
slowlog = /tmp/www_slow.log
request_slowlog_timeout = 1
php_admin_value[open_basedir] = /data/www:/tmp/

[www1]
listen = /tmp/www1.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
slowlog = /tmp/www1_slow.log
request_slowlog_timeout = 1
php_admin_value[open_basedir] = /data/wordpress:/tmp/

现在是curl的结果:
[root@wtest vhosts]# curl -x127.0.0.1:80 aaa.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Thu, 24 Mar 2016 09:42:26 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
location: forum.php

[root@wtest vhosts]# curl -x127.0.0.1:80 111.com -I
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.6.2
Date: Thu, 24 Mar 2016 09:42:52 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
Location: http://111.com/wp-admin/setup-config.php

但在windows端,我设置的192.169.1.200  www.aaa.com
但无法访问显示404,而直接访问192.169.1.200 则显示的是wordpress的内容
请各位帮忙分析下,这是为什么,为什么不能直接访问aaa.com的内容
2016-03-24 17:59 举报
已邀请:
0

乐橙306

赞同来自:

你把你的需求  详细的说一遍(即你想做什么)

aaa.conf     和 111.conf   都是监听的 80端口   麻烦你把你这个配置的参考文档发给我看看

正常的配置是  不同的conf配置文件监听不同的端口

比如 aaa.com  监听80   111.conf  监听 81
0

we14578

赞同来自:

乐橙306 发表于 2016-3-24 18:56
你把你的需求  详细的说一遍(即你想做什么)

aaa.conf     和 111.conf   都是监听的 80端口   麻烦你 ...

我想在windows端能够两个都能访问,我在windos端host中设置了 现在对应的是192.169.1.200。
我现在是以php 的pool 来限定了两个虚拟主机,应该跟监听端口没有关系吧。
我的nginx的主配置文件,是直接复制的铭哥的资料里的。你要是需要,我可以附在这里。

而我现在在IE访问www.aaa.com,显示的是HTTP 404
但是curl 是正常的
0

乐橙306

赞同来自:


  1. 需求大致是这样的  

  2. 看下我理解没

  3. 若客户端访问aaa.com 那么他就访问服务端/data/www 下的内容   

  4. 若客户端访问111.com 那么他就访问服务端/data/wordpress 下的内容





  5. 具体怎么实现

  6. [root@aliyun-63 conf.d]# pwd
  7. /etc/nginx/conf.d
  8. [root@aliyun-63 conf.d]# cat sundong.wang.conf
  9. server {
  10.     listen       80 default_server;
  11.     server_name  www.sundong.wang;
  12.     root   /usr/share/nginx/html;
  13.     index  index.html index.htm;
  14. }
  15. [root@aliyun-63 conf.d]# cat sundong.xyz.conf
  16. server

  17. {
  18.     listen 80;
  19.     server_name www.sundong.xyz;
  20.     index index.html index.htm index.php;
  21.     root /var/www/html;
  22. }
  23. [root@aliyun-63 conf.d]#

  24. [root@aliyun-63 conf.d]# curl  -I  www.sundong.wang/1.htm
  25. HTTP/1.1 200 OK
  26. Server: nginx/1.0.15
  27. Date: Fri, 25 Mar 2016 01:49:40 GMT
  28. Content-Type: text/html
  29. Content-Length: 11283
  30. Last-Modified: Thu, 24 Mar 2016 03:31:29 GMT
  31. Connection: keep-alive
  32. Accept-Ranges: bytes

  33. [root@aliyun-63 conf.d]# curl  -I  www.sundong.xyz/1.htm
  34. HTTP/1.1 200 OK
  35. Server: nginx/1.0.15
  36. Date: Fri, 25 Mar 2016 01:49:45 GMT
  37. Content-Type: text/html
  38. Content-Length: 96817
  39. Last-Modified: Fri, 25 Mar 2016 01:31:21 GMT
  40. Connection: keep-alive
  41. Accept-Ranges: bytes

  42. [root@aliyun-63 conf.d]#



0

乐橙306

赞同来自:

  1. [root@aliyun-63 conf.d]# cd  /usr/share/nginx/html
  2. [root@aliyun-63 html]# ll
  3. total 4064
  4. drwxr-xr-x 2 root root    4096 Mar 24 11:31 1_files
  5. -rw-r--r-- 1 root root 1239730 Mar 24 11:32 1_files.zip
  6. -rw-r--r-- 1 root root   11283 Mar 24 11:31 1.htm
  7. drwxr-xr-x 2 root root    4096 Mar 24 11:31 2_files
  8. -rw-r--r-- 1 root root 1420851 Mar 24 11:32 2_files.zip
  9. -rw-r--r-- 1 root root   26819 Mar 24 11:31 2.htm
  10. drwxr-xr-x 2 root root    4096 Mar 24 11:32 3_files
  11. -rw-r--r-- 1 root root 1370082 Mar 24 11:32 3_files.zip
  12. -rw-r--r-- 1 root root   53044 Mar 24 11:32 3.htm
  13. -rw-r--r-- 1 root root    3652 Jun 17  2015 404.html
  14. -rw-r--r-- 1 root root    3695 Jun 17  2015 50x.html
  15. -rw-r--r-- 1 root root    3698 Jun 17  2015 index.html
  16. -rw-r--r-- 1 root root     368 Jun 17  2015 nginx-logo.png
  17. -rw-r--r-- 1 root root    2811 Jun 17  2015 poweredby.png
  18. [root@aliyun-63 html]# cd  /var/www/html
  19. [root@aliyun-63 html]# ll
  20. total 3132
  21. drwxr-xr-x 2 root root    4096 Mar 25 09:31 1_files
  22. -rw-r--r-- 1 root root  217099 Mar 25 09:31 1_files.zip
  23. -rw-r--r-- 1 root root   96817 Mar 25 09:31 1.htm
  24. drwxr-xr-x 2 root root    4096 Mar 24 11:31 2_files
  25. -rw-r--r-- 1 root root 1420851 Mar 24 11:32 2_files.zip
  26. -rw-r--r-- 1 root root   26819 Mar 24 11:31 2.htm
  27. drwxr-xr-x 2 root root    4096 Mar 24 11:32 3_files
  28. -rw-r--r-- 1 root root 1370082 Mar 24 11:32 3_files.zip
  29. -rw-r--r-- 1 root root   53044 Mar 24 11:32 3.htm

  30. [root@aliyun-63 html]# curl  -I  www.sundong.wang/2.htm
  31. HTTP/1.1 200 OK
  32. Server: nginx/1.0.15
  33. Date: Fri, 25 Mar 2016 01:52:07 GMT
  34. Content-Type: text/html
  35. Content-Length: 26819
  36. Last-Modified: Thu, 24 Mar 2016 03:31:56 GMT
  37. Connection: keep-alive
  38. Accept-Ranges: bytes

  39. [root@aliyun-63 html]# curl  -I  www.sundong.wang/3.htm
  40. HTTP/1.1 200 OK
  41. Server: nginx/1.0.15
  42. Date: Fri, 25 Mar 2016 01:52:32 GMT
  43. Content-Type: text/html
  44. Content-Length: 53044
  45. Last-Modified: Thu, 24 Mar 2016 03:32:03 GMT
  46. Connection: keep-alive
  47. Accept-Ranges: bytes

  48. [root@aliyun-63 html]# curl  -I  www.sundong.xyz/3.htm
  49. HTTP/1.1 404 Not Found
  50. Server: nginx/1.0.15
  51. Date: Fri, 25 Mar 2016 01:52:40 GMT
  52. Content-Type: text/html
  53. Content-Length: 169
  54. Connection: keep-alive

  55. [root@aliyun-63 html]# curl  -I  www.sundong.xyz/2.htm
  56. HTTP/1.1 404 Not Found
  57. Server: nginx/1.0.15
  58. Date: Fri, 25 Mar 2016 01:52:46 GMT
  59. Content-Type: text/html
  60. Content-Length: 169
  61. Connection: keep-alive

  62. [root@aliyun-63 html]#
0

we14578

赞同来自:

我提问的原因是我在windows端设置的etc/hosts,192.169.1.200 www.aaa.com
而实际上我访问aaa.com出现的内容却是 111.com。
我用的使php-fpm两个不同的pool。
并且我在linux上curl的内容实际上是正确的,但是在windows端显示不正确。
我想知道 windows不正确的原因
0

369666951

赞同来自:

本帖最后由 369666951 于 2016-3-25 21:42 编辑

看起来配置没问题 啊 ,浏览器缓存?或者是 www的原因配置里面的域名没有带www
0

we14578

赞同来自:

本帖最后由 we14578 于 2016-3-25 22:24 编辑

域名,www.aaa.com,还有直接访问IP,192.169.1.200,我也试了,但是不知道为什么显示的就是111.com的内容
0

阿铭 管理员

赞同来自:

hosts  aaa.com也加上
0

we14578

赞同来自:

老师,我在host里面添加了,然后重新测试了,在IE里面还是有问题,但是在firefox里没有问题。
我觉着应该是IE的判断机制有问题。
问题解决了,测试的时候还是尽量不要使用IE
0

马力119

赞同来自:

我也遇到这个问题,原来问题在server_name这里,不但要写aaa.com,也要写上www.aaa.com 否则就不行!

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: