全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1898|回复: 7

小白 问个 NGINX 配置子域名问题

[复制链接]
发表于 2018-9-13 22:22:25 | 显示全部楼层 |阅读模式
需求: 同一IP, 80端口,多个子域名访问

         a.xxx.com 指向目录 var/www/html/a.xxx.com
         b.xxx.com 指向目录 var/www/html/b.xxx.com

我的做法是 修改 etc/nginx/sites-avaliable/default  如下

                       
server {
        listen 80 ;
        listen [::]:80 ;
        server_name a.xxx.com ;
       
        root /var/www/html/a.xxx.com;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

       

        location / {
        index index.html index.htm index.php default.html default.htm default.php;
        }
        location ~ .*\.php(\/.*)*$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        #fastcgi_pass 127.0.0.1:9000;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
       
        }
       
}





server {
        listen 80 ;
        listen [::]:80 ;
        server_name b.xxx.com ;
       
        root /var/www/html/b.xxx.com;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

       

        location / {
        index index.html index.htm index.php default.html default.htm default.php;
        }
        location ~ .*\.php(\/.*)*$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        #fastcgi_pass 127.0.0.1:9000;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
       
        }
       
}


问题是 nginx 无法成功重启,有错误,将第二个 80端口 改成其他可以正常启动,但是域名访问失效,只能通过端口来区分访问目录,在网上搜了一大把,没有一个靠谱的,这应该是最基础的了吧,往大神指点一二。不甚感激,搞得头大!
发表于 2018-9-14 09:09:05 | 显示全部楼层
试一试分开写
/etc/nginx/sites-avaliable/a
/etc/nginx/sites-avaliable/b
然后分别软连接到/etc/nginx/sites-enable
 楼主| 发表于 2018-9-14 09:15:07 来自手机 | 显示全部楼层
好的,我回去试试。谢谢大佬
 楼主| 发表于 2018-9-14 10:58:28 来自手机 | 显示全部楼层
试了下,不成功。
发表于 2018-9-14 17:40:51 来自手机 | 显示全部楼层
在第一个server的80端口后面加上reuse,具体的可以查看手册
 楼主| 发表于 2018-9-14 17:51:09 | 显示全部楼层
server {
        listen 80  reuse ;
        listen [::]:80 ;

结果:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
发表于 2018-9-14 18:13:04 | 显示全部楼层
whk0425 发表于 2018-9-14 17:51
server {
        listen 80  reuse ;
        listen [::]:80 ;


是 reuseport,记错了,不是reuse。。。
我一般会加一个default server,其他的server正常写,可以省好多麻烦
  1. server {
  2.     listen          80 fastopen=3 reuseport default;
  3.     listen          [::]:80  fastopen=3 reuseport default;
  4.     server_name    _;
  5. }
复制代码
 楼主| 发表于 2018-9-14 18:25:24 | 显示全部楼层
qytang 发表于 2018-9-14 18:13
是 reuseport,记错了,不是reuse。。。
我一般会加一个default server,其他的server正常写,可以省好多 ...

谢谢大佬,搞定了,感激涕零!!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-20 05:12 , Processed in 0.062108 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表