在nginx中提供多个目录

时间:2014-11-06 17:07:59

标签: php nginx

我正在尝试在我的vps上设置ngnix来提供不同的东西,例如

examplesite.com/(主要网站)

examplesite.com/pro/(子应用)

examplesite.com/ad/

我希望能够从这些目录中运行不同的php应用程序。

我的第一个任务是让examplesite.com/pro网站正常运行,但我遇到了问题。

请有人帮帮我吗?

我只是希望能够运行不同的东西。我正在/pro/目录上尝试安装prosper202。

我的default.conf文件:

server {

        listen 80;
        server_name .exmaple.com;
        root /usr/share/nginx/html;
        client_max_body_size 512M;

        # Default location settings
        location / {
            index index.php;
        }

        location /pro {
            index index.php;
            try_files $uri $uri/ pro/index.php?$args;
        }

        # Redirect server error pages to the static page /50x.html
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
            root /usr/share/nginx/html;
        }

        # Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead)
        location ~ \.php$ {
            # Prevent Zero-day exploit
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }


---------------------------ngnix.conf------------------------------------- 

user nginx; 
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}


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

    log_format  main  '$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;
    sendfile on;
    keepalive_timeout 65;
    include /etc/nginx/conf.d/*.conf;

}

我的error.log文件:

2014/11/06 11:51:41 [error] 3152#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.16.105.135, server: , request: "GET / HTTP/1.1", host: "IP" 2014/11/06 11:54:39 [error] 3218#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.176.105.135, server: , request: "GET / HTTP/1.1", host: "IP"

1 个答案:

答案 0 :(得分:0)

你的try_files指令中缺少斜线。

替换:

pro/index.php?$args

使用:

/pro/index.php$is_args$args