VPS侦探论坛

 找回密码
 注册
查看: 2608|回复: 2

各位大神,Nginx的二级域名到底怎么配置才对呀?

[复制链接]
发表于 2018-12-26 09:32:01 | 显示全部楼层 |阅读模式

大神求教:

LNMP 结构,域名xxx.com下想搞个二级域名abc.xxx.com
xxx.com 原来指向目录/usr/share/nginx/html
现在在想abc.xxx.com指向目录/usr/share/nginx/abc

没设二级域名abc.xxx.com时,访问正常!
设了二级域名abc.xxx.com后,访问xxx.com没问题!
但访问abc.xxx.com时,提示说"File not found"
如果是访问abc.xxx.com/info.html 是正常的,就是不能访问下面的*.php,提示"File not found"
如果把配置文件中的“root    /usr/share/nginx/abc” 改为跟nginx.conf的root一样,也能正常访问

各位大老,我哪里姿势不对了吗?求教〜

nginx.conf 文件的配置是这样的:
**********************************************************

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    client_max_body_size 32m;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        rewrite ^ https://$http_host$request_uri? permanent;
    }

    server {
        listen       443;
        server_name  xxx.com xxx.com;

        ... (这里配置SSL,省略了)

        root       /usr/share/nginx/html;
        location / {
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9900;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
   
    include /etc/nginx/conf.d/*.conf;
}


然后在 /etc/nginx/conf.d/ 目录下生成一个abc.conf 该配置是这样的:
**********************************************************

server {
    listen       443;
    server_name  abc.xxx.com;

    ... (这里配置SSL,省略了)

    root    /usr/share/nginx/abc;
    location / {
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9900;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}








美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2018-12-26 12:33:01 | 显示全部楼层

回复 1# 的帖子



难道坛子里没人知道吗?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2018-12-26 17:54:12 | 显示全部楼层

看你发的配置文件不是 https://lnmp.org 安装包安装的
看你这配置文件到处是问题,如果是用 https://lnmp.org 安装包安装的,自己乱改了文件,将配置文件恢复到原来的配置文件,按官网上的虚拟主机添加方法进行添加
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-23 07:26 , Processed in 0.025217 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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