【问题标题】:Getting rerouted to Welcome to nginx each time每次都重新路由到 Welcome to nginx
【发布时间】:2019-09-09 03:41:20
【问题描述】:

无法弄清楚为什么 nginx 会继续重定向到 Welcome to nginx 页面。我正在尝试安装和运行一个开源应用程序(问题 2 答案)。只是想先让它在我的虚拟机中本地运行。

我在一个 vagrant vm 机器上。运行 16.04 的 Ubuntu。我在本地机器上编辑了我的 /etc/hosts 文件以匹配我的 vagrant box 中的文件。我尝试了不同的教程以及 SO,但仍然重定向到欢迎页面

这是我的服务器文件

server {

    #Nginx should listen on port 80 for requests to yoursite.com
    listen 80;
    listen [::]:80;              

    #Create access and error logs in /var/log/nginx
    access_log /var/log/nginx/yoursite.access_log main;
    error_log /var/log/nginx/yoursite.error_log info;

    #Nginx should look in /var/www/q2a for website
    root /var/www/q2a.org/q2a/;


    #The homepage of your website is a file called index.php
     index.php;

    server_name local-q2a.org;         

    #Specifies that Nginx is looking for .php files
    location ~ \.php$ {
            #If a file isn’t found, 404
            try_files $uri =404;

            #Include Nginx’s fastcgi configuration
            include /etc/nginx/fastcgi.conf;

            #Look for the FastCGI Process Manager at this location
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;

            fastcgi_param HTTP_X_FORWARDED_FOR 
$http_x_forwarded_for;                                      
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
        }
}

我正在尝试让应用至少在本地运行。

【问题讨论】:

  • 使用nginx -t 测试您的配置文件。 index.php; 声明很可疑,您可能打算写 index index.php;

标签: php ubuntu nginx nginx-config question2answer


【解决方案1】:

server_name local-q2a.org; 放在指令listen 之后。删除文件/etc/nginx/sites-enabled/default。然后重新加载nginx:sudo nginx -t && sudo nginx -s reload.

我猜,nginx 只是无法识别您的主机名并将您发送到默认配置。

【讨论】:

  • 不,这没用。不要认为顺序对 nginx 很重要
【解决方案2】:

我想我会发布一个答案,以防有人遇到类似问题。下面是我的代码。我还必须从我的站点创建一个符号链接,以便我的站点启用。此外,我使用我的专用网络 vagrant 框将我的 etc 文件编辑到我想要的指定 URL。然后我很喜欢并将其与 ngrok 相关联,并将其发布在互联网上以用于演示目的。

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/question2answer;
    index  index.php index.html index.htm;
    server_name local-q2a.org www.local-q2a.org;

    client_max_body_size 100M;

    autoindex off;

    location / {
        try_files $uri @question2answer;
         }

    location @question2answer {
        rewrite  /index.php$uri last;
        }

    location ~* "^/index\.php(/|$)" {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
     }

    location ~* "\.php(/|$)" {
        rewrite ^ /index.php$uri last;
         }
}

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 2018-10-21
    • 2020-02-29
    • 2018-12-22
    • 2017-02-21
    • 1970-01-01
    • 2013-05-05
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多