ubuntu 每次都被重新路由到Welcome to nginx

xj3cbfub  于 2023-10-17  发布在  Nginx
关注(0)|答案(2)|浏览(148)

无法弄清楚为什么nginx继续重定向到欢迎来到nginx页面。我正在尝试安装和运行一个开源应用程序(问题2答案)。只是想让它先在我的虚拟机上本地运行。
我在一个流浪的虚拟机。Ubuntu 16.04.我在本地机器上编辑了/etc/hosts文件,以匹配我的vagrant box中的文件。我尝试了不同的教程,以及SO,但仍然重定向到欢迎页面
这是我的服务器文件

  1. server {
  2. #Nginx should listen on port 80 for requests to yoursite.com
  3. listen 80;
  4. listen [::]:80;
  5. #Create access and error logs in /var/log/nginx
  6. access_log /var/log/nginx/yoursite.access_log main;
  7. error_log /var/log/nginx/yoursite.error_log info;
  8. #Nginx should look in /var/www/q2a for website
  9. root /var/www/q2a.org/q2a/;
  10. #The homepage of your website is a file called index.php
  11. index.php;
  12. server_name local-q2a.org;
  13. #Specifies that Nginx is looking for .php files
  14. location ~ \.php$ {
  15. #If a file isn’t found, 404
  16. try_files $uri =404;
  17. #Include Nginx’s fastcgi configuration
  18. include /etc/nginx/fastcgi.conf;
  19. #Look for the FastCGI Process Manager at this location
  20. fastcgi_pass unix:/run/php/php7.1-fpm.sock;
  21. fastcgi_param HTTP_X_FORWARDED_FOR
  22. $http_x_forwarded_for;
  23. fastcgi_split_path_info ^(.+\.php)(/.*)$;
  24. }
  25. }

我试图让应用程序至少在本地运行。

k5ifujac

k5ifujac1#

server_name local-q2a.org;放在listen指令之后。删除文件/etc/nginx/sites-enabled/default。然后重新加载nginx:sudo nginx -t && sudo nginx -s reload
我猜,nginx只是不识别你的主机名,并将你发送到默认配置。

xbp102n0

xbp102n02#

我想我会发布一个答案,以防有人在为类似的问题而挣扎。下面是我的代码。我还必须创建一个符号链接从我的网站提供给我的网站启用。此外,我用我的私人网络流浪汉框编辑我的etc文件到我想要的指定URL。然后我花了点心思,把它链接到了ngrok上,并在互联网上进行了演示。

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. root /var/www/html/question2answer;
  5. index index.php index.html index.htm;
  6. server_name local-q2a.org www.local-q2a.org;
  7. client_max_body_size 100M;
  8. autoindex off;
  9. location / {
  10. try_files $uri @question2answer;
  11. }
  12. location @question2answer {
  13. rewrite /index.php$uri last;
  14. }
  15. location ~* "^/index\.php(/|$)" {
  16. include snippets/fastcgi-php.conf;
  17. fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. include fastcgi_params;
  20. }
  21. location ~* "\.php(/|$)" {
  22. rewrite ^ /index.php$uri last;
  23. }
  24. }
展开查看全部

相关问题