找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 73|回复: 9

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

[复制链接]

76

主题

488

回帖

1236

积分

金牌会员

积分
1236
发表于 2018-12-25 22:59:55 | 显示全部楼层 |阅读模式
大神求教:

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;
    }
}

回复

使用道具 举报

25

主题

257

回帖

613

积分

高级会员

积分
613
发表于 2018-12-25 23:04:07 | 显示全部楼层
本帖最后由 mark 于 2018-12-25 23:06 编辑



回复

使用道具 举报

108

主题

1999

回帖

4438

积分

论坛元老

积分
4438
发表于 2018-12-25 23:15:06 | 显示全部楼层
abc改fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; ->fastcgi_param  SCRIPT_FILENAME  /use/share/nginx/abc$fastcgi_script_name; 不明原因$document_root毛生效
回复

使用道具 举报

76

主题

488

回帖

1236

积分

金牌会员

积分
1236
 楼主| 发表于 2018-12-25 23:19:47 | 显示全部楼层

xfspace 发表于 2018-12-25 23:15

abc改fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; ->fastcgi_param  SCRIPT_FIL ...

改了还是提示“File not found”
看日志提示:
2018/12/25 23:09:41 [error] 5#5: *20 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client:
回复

使用道具 举报

23

主题

297

回帖

695

积分

高级会员

积分
695
发表于 2018-12-25 23:15:00 | 显示全部楼层
跑PHP换nginx干嘛

回复

使用道具 举报

76

主题

488

回帖

1236

积分

金牌会员

积分
1236
 楼主| 发表于 2018-12-25 23:23:48 | 显示全部楼层

烟花三月 发表于 2018-12-25 23:23

跑PHP换nginx干嘛

呀?跑PHP不用Nginx?没看明白你说的
回复

使用道具 举报

23

主题

297

回帖

695

积分

高级会员

积分
695
发表于 2018-12-25 23:35:30 | 显示全部楼层

wishost 发表于 2018-12-25 23:35

呀?跑PHP不用Nginx?没看明白你说的

nginx跑静态优势很大.....跑php还是apache..当然...量不大没多大区别.
回复

使用道具 举报

19

主题

137

回帖

369

积分

中级会员

积分
369
发表于 2018-12-25 23:23:00 | 显示全部楼层
按下权限问题
回复

使用道具 举报

22

主题

517

回帖

1116

积分

金牌会员

积分
1116
发表于 2018-12-26 00:33:55 | 显示全部楼层
配置文件错了,到LNMP.ORG的论坛上问一下就是了。

nginx跑PHP没问题,关键在于config文件和php-fpm的配置,配得好完全没问题,配错一点,502错误常见。

apache也可以走php-fpm模式。
回复

使用道具 举报

23

主题

297

回帖

695

积分

高级会员

积分
695
发表于 2018-12-25 23:35:00 | 显示全部楼层

aRNoLD 发表于 2018-12-26 01:17

配置文件错了,到LNMP.ORG的论坛上问一下就是了。

nginx跑PHP没问题,关键在于config文件和php-fpm的配置 ...

好的,谢谢看下php-fpm  启动的用户的 跟nginx的用户是不是同一个 不是的话  会报那个错
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2025-5-9 10:35 , Processed in 0.020659 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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