我的 nginx.conf 有什么问题

我的 nginx.conf 有什么问题

我正在尝试为虚拟主机创建一个子目录。例如 xxx.xxx.xxx/vhost1 和 xxx.xxx.xxx/vhost2。我有以下配置文件:

user www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

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

    server {
        listen   80 default;

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

        location / {
                root   /var/www/nginx-default;
                index  index.html index.htm;
        }

        location /adminapi {
                if (-f $request_filename) {
                        break;
                }

                rewrite  ^/(.*)$  /index.php?$1  last;
                root   /var/www/api/src/frapi/admin/public;
                index  index.php;
        }

        location /api {
                 if (-f $request_filename) {
                        break;
                 }

                rewrite  ^/(.*)$  /index.php?$1  last;
                root   /var/www/api/src/frapi/admin/public;
                index  index.php;
        }

        location /phpmyadmin {
                 root   /usr/share/phpmyadmin;
                 index  index.php;

                 fastcgi_pass 127.0.0.1:9000;
                 fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
                 include /etc/nginx/fastcgi_params;
                 fastcgi_param SCRIPT_NAME /index.php;
        }

        location /doc {
                root   /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location /images {
                root   /usr/share;
                autoindex on;
        }

        #error_page  404  /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #       root   /var/www/nginx-default;
        #}

        # 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;
                fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
                include fastcgi_params;
        }

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


}

xxx.xxx.xxx/phpmyadmin 可以工作,但是布局错误..我猜它找不到 css 和图像...我需要更改什么?

其他 xxx.xxx.xxx/vhost 根本不起作用

答案1

对于您的 phpmyadmin 找不到它的 CSS,您应该能够通过使用 Firebug 或 Chrome 开发人员工具等客户端工具来诊断,以查看哪些请求失败以及它们请求的 URI,或者通过跟踪/var/log/nginx/access.log/var/log/nginx/error.log查看来自服务器端的相同信息。

对于您关于 nginx 不显示http://sample.com/vhost1等的另一个问题,您的根目录配置为从 读取/var/www/nginx-default。因此,您应该有一个目录,其中包含名为或 的/var/www/nginx-default/vhost1文件。或者,如果您希望 URI指向不同的文件系统位置,只需在配置文件中添加另一个块,例如:index.htmlindex.htm/vhost1

location /vhost1 {
    root   /home/sample/www/vhost1;
    index  index.html;
}

location /vhost2 {
    root   /var/www/vhost2;
    index  index.html;
}

相关内容