Nginx - 根文件夹

时间:2015-07-25 14:24:40

标签: nginx

当我在http://myIP访问页面时,我看到文件夹

中的文件
var/www/html

而不是

var/www/html/src/public

我在/etc/nginx/sites-available/default中设置了以下设置:

root /var/www/html/src/public;
index index.html index.htm;

并重启了nginx。

可能有什么不对?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您需要在以下位置定义文档根目录:

  

/etc/nginx/nginx.conf

或者在虚拟主机配置文件中定义它:

  

/etc/nginx/conf.d/default.conf

以下是default.conf文件设置示例:

server {
    listen       80;
    listen       443 ssl;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    server_name  adamsawesomewebsite.tk;
    root   /var/www/vhosts/adamsawesomewebsite.tk/httpdocs;
    index  index.php index.html;
    #charset koi8-r;
    #access_log  /var/log/nginx/access.log  main;

    # redirect server error pages to the static page /40x.html
    #
    #error_page  404              /404.html;
    #location = /40x.html {
    #}
    location / {
    try_files $uri $uri/ /index.php?q=$request_uri;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}