简体   繁体   English

Nginx虚拟主机不起作用

[英]Nginx virtual hosts not working

I recorded a video https://youtu.be/dmezVzASr5A 我录制了一个视频https://youtu.be/dmezVzASr5A

I have: 我有:

  • linux ubuntu 16.04 (Lubuntu) linux ubuntu 16.04(Lubuntu)
  • nginx 1.10 nginx 1.10
  • php7.0-fpm php7.0-fpm
  • php7.0 php7.0
  • mysql 5.7 的MySQL 5.7

I did: 我做了:

  • created domain /etc/hosts (test2.test) 创建域/ etc / hosts(test2.test)
  • created virtual hosts withing sites-available folder (test2.test file) 创建具有站点可用文件夹的虚拟主机(test2.test文件)
  • restarted, reloaded nginx server (sudo service nginx stop...restart...reload) 重新启动,重新加载了nginx服务器(sudo服务nginx停止...重新启动...重新加载)
  • created symlink ln -s /etc/nginx/sites-available/test2.test /etc/nginx/sites-enabled/ 创建的符号链接ln -s /etc/nginx/sites-available/test2.test /etc/nginx/sites-enabled/

symlink proof: 符号链接证明:

dima@dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -ls /etc/nginx/sites-enabled
total 0
0 lrwxrwxrwx 1 root root 34 май 21 16:33 default -> /etc/nginx/sites-available/default
0 lrwxrwxrwx 1 root root 37 май 21 16:44 test2.test -> /etc/nginx/sites-available/test2.test

Problem is when i try to open in browser http://test2.test , i get: 问题是,当我尝试在浏览器http://test2.test中打开时,我得到了:

404 Not Found

nginx/1.10.0 (Ubuntu)

This files are not opening: 此文件未打开:

  • index.html index.html
  • test.html test.html
  • index.php index.php

within /var/www/html i have info.php with content <?php echo phpinfo(); ?> /var/www/html我有info.php ,内容为<?php echo phpinfo(); ?> <?php echo phpinfo(); ?> . <?php echo phpinfo(); ?> http://localhost/info.php successfully displays php info. http://localhost/info.php成功显示php信息。

My permissions: 我的权限:

dima@dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima     dima     4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data  111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data   26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data    5 май 21 16:59 test.html
dima@dima-Lenovo-G50-30:~/www/nginx/test2.ru$ 

My virtual hosts: 我的虚拟主机:

server {
    listen 80;
    listen [::]:80;

    server_name test2.test;

    root /home/dima/www/nginx/test2.ru;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
        #autoindex on;
    }
}

nginx logs: nginx日志:

error.log.1: many errors like: error.log.1:许多错误,例如:

2016/05/26 08:46:28 [crit] 1066#1066: *1 stat() "/home/dima/www/nginx/test2.ru/" failed (13: Permission denied), client: 127.0.0.1, server: test2.test, request: "GET / HTTP/1.1", host: "test2.test"

ls -la: ls -la:

dima@dima-Lenovo-G50-30:~/www/nginx$ ls -la
total 16
drwxrwxr-x  4 dima     dima     4096 май 21 13:14 .
drwxrwxr-x 10 dima     dima     4096 май 21 12:52 ..
drwxrwxr-x  5 dima     dima     4096 май 21 12:52 test1.ru
drwxr-xr-x  2 www-data www-data 4096 май 21 16:59 test2.ru
dima@dima-Lenovo-G50-30:~/www/nginx$ 

within test2.ru folder: 在test2.ru文件夹中:

dima@dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima     dima     4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data  111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data   26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data    5 май 21 16:59 test.html
dima@dima-Lenovo-G50-30:~/www/nginx/test2.ru$ 

UPD I have fixed. 我已修复UPD It was permissions problem. 这是权限问题。 I changed some permisisions and it worked, but i don't know and remvemebr exactly what i did, but it works 我更改了一些权限,但它确实起作用,但我不知道并完全记得我所做的事情,但是它有效

Maybe you can try to give execute access to the files in that /home/dima/www/nginx/test2.ru folder. 也许您可以尝试授予对/home/dima/www/nginx/test2.ru文件夹中文件的执行访问权限。 Nginx needs to execute the php files, not only read the files. Nginx需要执行php文件,而不仅仅是读取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM