301永久移动,错误设置nginx

时间:2019-03-13 08:26:02

标签: nginx

我尝试在Ubuntu 18下的Nginx中设置多个域 与后续步骤x: 1)创建应用目录

mkdir /var/www/votes.com
cd /var/www/votes.com
sudo nano /var/www/votes.com/index.php

带有文字

File <b>/var/www/votes.com/index.php </b> index
<?php 
echo ‘Hello all!’;

2)创建/etc/nginx/sites-available/votes.com

sudo nano /etc/nginx/sites-available/votes.com 

内容:

upstream votes-backend { # Lets you define a group of servers
   server unix:/var/run/php7.2-fpm.sock;
}

server {
   listen 80;

   root /var/www/votes.com;
   index index.php;

   server_name votes.com;
   #  rewrite ^ http://votes.com$request_uri? permanent; #301 redirect  TO UNCOMMENT

   # We keep this block, because it doesn't make sense to pass
   # everything to PHP.
   location / {
      try_files $uri $uri/ =404;
   }

   location ~ \.php$ {
     fastcgi_split_path_info ^(.+\.php)(/.+)$; # this defines a regular expression to separate the SCRIPT_FILENAME and PATH_INFO for later use
     try_files $uri =404; # OR Set cgi.fix_pathinfo=0 in php.ini (for security)
     fastcgi_pass votes-backend; # OR unix:/var/run/php7.2-fpm.sock OR 127.0.0.1:9000
     fastcgi_index index.php; # appends index.php to a URI ending with a slash
     include fastcgi_params;
   }

}

3)编辑/ etc / hosts

sudo nano /etc/hosts
add line :
127.0.0.3   localhost votes.com

4)创建符号链接:

sudo ln -s /etc/nginx/sites-available/votes.com /etc/nginx/sites-enabled/

检查:

cd /etc/nginx/sites-enabled/
ls

5)重新启动nginx服务

sudo service nginx restart
sudo systemctl restart php7.2-fpm

但是重新启动并引用站点

curl votes.com

我遇到错误:

$ sudo systemctl restart php7.2-fpm
$ sudo service nginx restart
ubuntu@ip-172-31-39-38:/etc/nginx/sites-enabled$ curl votes.com
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>

谷歌搜索,我在下一步找到了一个决定:

   server_name votes.com;
   rewrite ^ http://votes.com$request_uri? permanent; #301 redirect 

然后取消注释配置文件中的上述行,然后重新启动服务位,我再次遇到相同的错误。

如何解决?

谢谢!

0 个答案:

没有答案