【问题标题】:php and nginx on virtual private server configuration problem - ip works but not domainphp 和 nginx 上的虚拟专用服务器配置问题 - ip 有效但域无效
【发布时间】:2021-07-30 11:52:49
【问题描述】:

我的 VPS 设置无法正常工作。

环境:Ubuntu 18.04、php7.4、postgresql 和 nginx

服务器的 IP 地址解析成功并显示默认的“成功”页面。但是,我想用来指向服务器的域不起作用,并且解析为 404。我觉得这是一个简单的修复,但经过一天的搜索我还没有找到它。

感谢您的帮助!

疑难解答:

windows 上的 nslookup 将域名解析为正确的 IP 地址(我可以只用域名 ssh 进入服务器)

在我的浏览器中使用域时仍然找不到该域。这是/etc/nginx/sites-available/temp.domain:

    server {
        listen 80;

        server_name temp.domain;

        root /var/www/temp.domain/public_html;

        index index.php index.html;

        access_log /var/log/nginx/temp.domain.access.log;
        error_log /var/log/nginx/temp.domain.error.log;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }

        location ~ \.php {
            fastcgi_index index.php;
            fastcgi_pass unix:/usr/local/var/run/php-fpm.socket;

            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }

默认配置:

    server {
            listen 80 default_server;
            listen [::]:80 default_server;
     root /var/www/html;

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

            server_name 192.169.0.1; #temp ip address

            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    try_files $uri $uri/ =404;
            }

            # pass PHP scripts to FastCGI server
            #
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
            #
            #       # With php-fpm (or other unix sockets):
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            #       # With php-cgi (or other tcp sockets):
            #       fastcgi_pass 127.0.0.1:9000;
            }

            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                    deny all;
            }
    }

【问题讨论】:

  • 为什么你有两个server 块?此外,server_name 192.169.0.1; 看起来不正确,因为 IP 地址不是名称。
  • 所以把所有东西都放在一个服务器块中?我屏蔽了 IP 地址。
  • 是的,尝试只使用一个服务器块和正确的server_name。即使通过 IP 访问也将使用此块。

标签: php ubuntu nginx


【解决方案1】:

必须安装 php-config,然后确保 php.ini 启用了 postgresql 扩展。还必须修复 nginx 站点可用/默认中的服务器块

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 2014-02-16
    • 2017-04-07
    • 2016-12-19
    • 1970-01-01
    • 2021-06-15
    相关资源
    最近更新 更多