我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。

我最近开始使用nginx,但我似乎找不到默认的公共web根。

我在哪里可以找到nginx的默认公共web根?


当前回答

你可以简单地将nginx的根文件夹映射到你的网站的位置:

nano /etc/nginx/sites-enabled/default

在默认文件中,在服务器标签中寻找根,并更改网站的默认文件夹,例如,我的网站是在/var/www

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www; <-- Here!
...

当我在评估nginx, apache2和lighttpd时,我把它们都映射到我的网站/var/www.我发现这是最有效的评估方法。

然后可以启动/停止您选择的服务器,并查看哪个执行得最好。

如。

service apache2 stop
service nginx start

顺便说一下,nginx实际上非常快!

其他回答

*默认页面web分配在var/www/html *默认配置服务器etc/nginx/sites/ available /nginx.conf

server {

    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.php;

    server_name _;

    location /data/ {
        autoindex on;
    }

    location /Maxtor {
        root /media/odroid/;
        autoindex on;

    }

        # This option is important for using PHP.
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    }
}

*默认配置服务器etc/nginx/nginx.conf

内容. .

user www-data;
worker_processes 8;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

IP客户端的默认访问日志var/log/nginx/…

对于AWS EC2 Linux,您将在这里找到:

/usr/share/nginx

如果你需要找到编译时定义的nginx公共根文件夹,你可以检查你的access.log文件。

打开nginx.conf 找到log_format指令 log_format的值是一个模板字符串,用于将信息写入access.log文件。您可以在这个模板字符串中添加$document_root变量,以将默认的www根位置记录到文件中。

下面是来自nginx.conf的http部分的一个例子,修改了log_format指令,$document_root被添加在字符串的开头:

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

                  ## ADD $document_root HERE ##
        log_format  main  '$document_root $remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;

        etc. .......

然后备份conf.d目录下的所有配置文件*.conf,并创建配置文件test.conf,如下所示: 服务器{ 听80; server_name主机; } 在“/etc/hosts”文件中增加如下一行:127.0.0.1 localhost 重载nginx配置:nginx -s重载 发送GET请求到http://localhost: curl http://localhost 查看access.log的最后一个字符串:tail -n 1 /var/log/nginx/access.log

下面是该命令的输出示例,其中/etc/nginx/html是编译时定义的默认文档根:

    /etc/nginx/html 127.0.0.1 - - [15/Mar/2017:17:12:25 +0200] "GET / HTTP/1.1" 404 169 "-" "curl/7.35.0" "-"

运行nginx -V命令,查找——前缀。使用该条目定位默认路径。

nginx的默认web文件夹取决于你如何安装它,但通常它在这些位置:

/usr/local/nginx/html
/usr/nginx/html