nginx - nginx 上的虚拟主机无法按预期运行

标签 nginx centos web-deployment centos7 vhosts

我的域名注册商的 DNS 访问我的服务器并获取 nginx 默认页面,因此配置正确

我复制了一个当前正在工作的 nginx 虚拟主机,更改了 server_name和 conf 文件的名称,仅此而已。

差异:

diff 701sm.club.conf drz400.info.conf 
3c3
<   server_name www.701sm.club 701sm.club;
---
>   server_name www.drz400.info drz400.info;

然后我重新启动了nginx。

这是整个无法运行的虚拟主机:
server {
    listen  80;
    server_name www.701sm.club 701sm.club;
    index index.php index.html index.htm;

    access_log /var/www/drz400.info/logs/access.log;
    error_log /var/www/drz400.info/logs/error.log;

    location / {
        root /var/www/drz400.info/production;
    }

    location ~ \.php$ {
        root /var/www/drz400.info/production;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

两个网站都应该点击我的.../production/index.html ,但只有一个。这里有什么问题?

最佳答案

请尝试以下代码,

server {
    listen  80;
    server_name www.701sm.club 701sm.club;
    index index.php index.html index.htm;

    access_log /var/www/drz400.info/logs/access.log;
    error_log /var/www/drz400.info/logs/error.log;
    root /var/www/drz400.info/production;

    location / {
        try_files $uri /index.html;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

关于nginx - nginx 上的虚拟主机无法按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39908908/

相关文章:

php - 使用 SSL 的 nginx 反向代理背后的 Docker 上的 Wordpress

nginx - 无法使用 --from-code 选项创建 OpenShift 应用程序

nginx - 让 nginx 检查 url 中的参数

java - Centos-8 JAVA 代码不执行程序和 JAVAC 命令不工作

centos - 如何公开访问 RabbitMq

php - 在 Cloud Foundry 上部署开源 CMS 'my little forum'(需要 PHP 和 MySQL)

php - 在 OpenShift 上部署 Laravel 应用程序

nginx - 如何查看 pod 是否超出其 CPU 限制?

ruby-on-rails - ROR 在 CentOS 上的安装

javascript - 使用 AngularJS 服务共享数据