每次都重新路由到Welcome to Nginx

时间:2019-04-18 18:52:25

标签: php ubuntu nginx nginx-config question2answer

无法弄清为什么nginx继续重定向到“欢迎使用nginx”页面。我正在尝试安装并运行一个开源应用程序(question2答案)。只需尝试使其首先在我的VM中本地运行。

我在一个无所事事的虚拟机上。运行16.04的Ubuntu。我在本地计算机上编辑了/ etc / hosts文件,以匹配流浪汉框中的文件。香港专业教育学院尝试了不同的教程以及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)(/.*)$;
        }
}

我正在尝试使该应用程序至少在本地运行。

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

如果有人遇到类似问题,我应该发布答案。下面是我的代码。我还必须从可用站点启用的站点创建符号链接。另外,我用我的私人网络游民报名框将我的etc文件编辑为我想要的指定URL。然后,我开始幻想并将其链接到ngrok,并将其发布到Internet上以进行演示。

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