一个 IP ,多个网站,如何配置?
ubuntu 14.04 nginx 1.80 php5-fpm
一个网站的时候正常,在 sites-available 再添加一个配置文件的时候,全部无法访问,请教如何正确配置
|  |      1cxbig      2015-09-16 23:34:50 +08:00 监听同样的端口 :80 和 :443 ,然后 ServerName 不一样的就行,指定不一样的 Directory 路径。 | 
|  |      2Daddy      2015-09-16 23:35:05 +08:00 是放 conf 的鏈接,不是 conf | 
|      3Scholer      2015-09-16 23:35:14 +08:00 server_name 想加多少加多少 | 
|  |      4cxbig      2015-09-16 23:37:37 +08:00 sites-available 是让你准备更多的独立的配置文件 你要让它们生效,需要连接到 sites-enabled ,然后重启 nginx 服务 | 
|  |      5linar OP | 
|      6Starduster      2015-09-16 23:39:31 +08:00  1 在 nginx.conf 里添加不同 Server 区块,或者在 conf.d/下添加独立的文件 server { listen 80; server_name aaa; root /xxx/aaa/; } server { listen 80; server_name bbb; root /xxx/bbb/; } http://nginx.org/en/docs/http/server_names.html | 
|  |      7Daddy      2015-09-16 23:45:46 +08:00 nginx 比較搞,不同版本都有变化,/usr/share/nginx 目录有,/etc/nginx 目录也有,都不统一的。我就是不喜欢,统一用一键包,就算只装一个 nginx 也是。  我记得是需要用 ln 做一下链接的。默认给的也是一个 ln 链接 | 
|      9fengdra      2015-09-16 23:51:42 +08:00  1 | 
|  |      10cxbig      2015-09-16 23:53:54 +08:00 LZ 说了有 sites-available ,那么肯定还有个 sites-enabled , link 上就好,分散安排不容易冲突,都写一个文件里太乱 | 
|  |      11Daddy      2015-09-16 23:57:26 +08:00 @loveminds 找死人的,我说怎么找不着目录,难道装出问题了?还有呢,一会是 conf.d ,一会是 sites-available , conf.d 是直接放 conf ,而 sites-available 是弄成软链接,我 X | 
|  |      12linar OP @cxbig 我就是建立了不同的配置文件在 sites-available,然后 ln 到 sites-enabled ,然后,然后就都无法访问了。 刚开始只添加一网站,可以正常访问,当我再添加一个配置文件到 sites-available ,并且 ln 后,两个网站就都无法访问了。。。 | 
|      14billlee      2015-09-17 00:03:29 +08:00 首先看看日志里报了什么错吧 | 
|  |      15cxbig      2015-09-17 00:04:37 +08:00 @linar 以下两个语法都可以: 1. sites-enabled$ sudo ln -s ../sites-available/site1 . 2. ~$ sudo ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/ 如果你确定链接没有问题,请检查每个配置文件的语法是不是有错 | 
|  |      16linar OP @cxbig ln -s /etc/ngixn/sites-available/xxx /etc/nginx/sites-enabled/xxx 而且一旦我把后来添加的配置文件删除,重启 nginx 后,第一个网站就又恢复正常了 | 
|  |      18XiaoxiaoPu      2015-09-17 00:07:56 +08:00 @Daddy 其实 Nginx 不搞, Nginx 自身是没有 sites-available 这种东西的,连 conf.d 都没有,只有一个 /etc/nginx/nginx.conf ,这些文件夹都是各个 debian 系, rhel 系发行版打包时自己加上的。 | 
|  |      19linar OP @cxbig  2015/09/16 23:19:37 [warn] 1902#0: conflicting server name "www.xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:19:37 [warn] 1902#0: conflicting server name "xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:19:37 [emerg] 1902#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 2015/09/16 23:19:37 [warn] 1905#0: conflicting server name "www.xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:19:37 [warn] 1905#0: conflicting server name "xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:19:37 [emerg] 1905#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 2015/09/16 23:22:33 [warn] 2098#0: conflicting server name "www.xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:22:33 [warn] 2098#0: conflicting server name "xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:22:33 [emerg] 2098#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 2015/09/16 23:41:57 [emerg] 3139#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 2015/09/16 23:43:09 [warn] 3287#0: conflicting server name "www.xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:43:09 [warn] 3287#0: conflicting server name "xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:43:09 [warn] 3287#0: conflicting server name "www.xxx2.com" on 0.0.0.0:80, ignored 2015/09/16 23:43:09 [warn] 3287#0: conflicting server name "xxx2.com" on 0.0.0.0:80, ignored 2015/09/16 23:43:09 [emerg] 3287#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 2015/09/16 23:45:50 [warn] 3529#0: conflicting server name "www.xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:45:50 [warn] 3529#0: conflicting server name "xxx.com" on 0.0.0.0:80, ignored 2015/09/16 23:45:50 [warn] 3529#0: conflicting server name "www.xxx2.com" on 0.0.0.0:80, ignored 2015/09/16 23:45:50 [warn] 3529#0: conflicting server name "xxx2.com" on 0.0.0.0:80, ignored 2015/09/16 23:45:50 [emerg] 3529#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 | 
|  |      20Daddy      2015-09-17 00:13:18 +08:00 @XiaoxiaoPu 没研究,只是看着就烦,变来变去的,目录一会是 /etc/nginx ,一会儿又去了 /usr/share/nginx ,还有 /usr/local/nginx ,然后干脆就统一用自己熟悉的一键包安装 nginx ,方便自己。 | 
|  |      21cxbig      2015-09-17 00:16:07 +08:00 | 
|  |      22jarlyyn      2015-09-17 00:16:49 +08:00 这个都不会的话,千万别用 nginx. 应为你估计也没法把.htaccess 里的安全配置改成 nginx 的 | 
|  |      24Daddy      2015-09-17 00:44:31 +08:00 @msg7086 半桶水,不想记太多把自己都搞蒙了,会一个就可以了,其他慢慢学习消化吧。 就比如这个问题,这个坑踩过,所以第一时间还是能猜到 LZ 是软链接那里弄错了,而不是乱贴 conf | 
|  |      25stanhou      2015-09-17 01:05:57 +08:00 这种最基本的问题应该自己去查手册 | 
|  |      26iyaozhen      2015-09-17 01:28:39 +08:00 我觉得这个问题默认的 conf 文件里面就有写呀。去掉注释就能运行 | 
|      27oojiayu      2015-09-17 01:30:28 +08:00 via Smartisan T1 安装个 AMH 不就完了么,至于那么麻烦? | 
|  |      28jamesliu96      2015-09-17 01:41:32 +08:00 在 http {} 里面加 server {} | 
|  |      29icloudnet      2015-09-17 04:52:03 +08:00 一直是 Apache 死忠,所以也是 centos 死忠,这段时间搞树莓派,用了 Apache2 了,还是不习惯,但是还是不用 nginx ,虽说 nginx 占用内存少点,主要还是再学习成本比 Apache 要高。 | 
|  |      30molinxx      2015-09-17 05:21:36 +08:00 via iPhone AMH 、 LuManager 、 WDCP ,不然来个 LNMP 一键包也行,生产环境最好等自己在测试环境折腾明白了再上。 | 
|  |      31Solael      2015-09-17 05:43:29 +08:00 | 
|  |      32ToysMall      2015-09-17 07:39:59 +08:00 via iPhone 这种水平就来? | 
|      33XianZaiZhuCe      2015-09-17 08:27:10 +08:00 这东西百度一下不太难的 | 
|      34shulen      2015-09-17 08:31:55 +08:00 | 
|      35fengyqf      2015-09-17 09:23:57 +08:00 | 
|  |      36flydogs      2015-09-17 09:31:35 +08:00 lnmp 一键安装, 然后可以用命令添加网站 /域名。 | 
|      39lightforce      2015-09-17 10:29:54 +08:00 ln -s .../sites-available/xxx .../sites-enabled/ | 
|      41fengyqf      2015-09-17 15:42:52 +08:00 @loveminds 你的意思是: 手工编译的包,其配置文件应该写到 /etc/软件名字 /xxx.conf 如果你的配置文件名字正好跟系统包管理的文件名字一致,包管理工具你认为你装过这个包,在做包 update 时,可能给你把这个包安装上。 我以为遇到过类似情况,自己编译的新版本 php ,然后 yum update 后,我的配置被覆盖了 | 
|      43ys0290      2015-09-17 17:30:56 +08:00 via iPhone 多看 log | 
|  |      44hippoboy      2015-09-17 17:49:44 +08:00 楼上好多人说了,server name |