1

我正在尝试从 XAMPP 迁移到 Nginx 网络服务器。我曾经有多个使用 Xampp 运行的网站,每个 Web 文件夹都位于 xampp/htdocs 文件夹下。例如,我将以 [code]http://myserver/site1[code] 和 [code]http://myserver/site2[code] 访问站点(yii 网站),它们将从 site1 和htdocs 下的 site2 文件夹。但我无法在 nginx 中设置它。我已将根文件夹的默认配置设置为 /etc/share/nginx/www (并且 site1 和 site2 文件夹位于 www 下),当我使用 nginx 以相同的方式访问时,网页给出错误消息“未指定输入文件”。我了解在 nginx 中设置了多个站点,具有不同的域名和不同的根文件夹,但是有可能有类似xampp的配置吗?因为我在我的本地网络上测试这个,我不想为此设置多个域名。

4

3 回答 3

2

最新 nginx 版本的配置非常简单。首先,您应该编辑nginx/conf/nginx.conf并确保您有类似include vhosts/*.conf;内部http {部分的内容。这将使 nginx 在vhosts.

此外,最好声明以下内容,http {不要为每个单独的配置重复它:

gzip  on;
charset utf-8;
index index.php index.htm index.html;

然后在nginx/conf/vhosts/mydomain.com.conf

server {
    listen       80;
    server_name  mydomain.com;
    root    /var/www/mydomain.com/www;

    location / {
        try_files   $uri $uri/ /index.php?$args; # Redirect everything that isn't real file to index.php including arguments.
    }

    location ~ \.php$ {
        include fastcgi.conf; # that's if you have one of latest versions of nginx. If not, see below
        fastcgi_pass   127.0.0.1:9000; # or pass through socket if it's how you've configured php-fpm
    }

    location ~ /\.(ht|svn) {
        deny all;
    }
}

如果你没有fastcgi.conf这里,它是:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

现在唯一剩下的就是添加mydomain.com到您的主机文件中,以便在本地识别它。

于 2013-11-06T21:48:05.923 回答
1

这很简单。

删除您的数据库,压缩它们,再次导入它们或使用 mysql -u root -p BASENAME < /the/path/BASEDROP.sql

然后只需移动您的默认目录,如 /var/www/html 并使用 chmod 0777 -R /the/path 将权限设置为 0777 或更少,并使用 chown www-data:www-data -R /the/path 然后重新启动你的系统。

于 2021-04-29T20:14:33.463 回答
0

嗯,经过一番苦苦挣扎,我终于找到了理想的配置。我知道这不是推荐的设置,但这对我来说是个问题(nginx 有多个站点作为子目录)并且必须找到解决方案。

location /Site1/ {
            root /usr/share/nginx/www/Site1;
           try_files $uri $uri/ /index.php?$query_string;
    }

    # the images need a seperate entry as we dont want to concatenate that with index.php      
    location ~ /Site1/.+\.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
            root /usr/share/nginx/www/Site1;
    }
    # pass the PHP scripts to FastCGI server
    location ~ /Site1/.+\.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            allow 127.0.0.1;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #       # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
    }
location /Site3/ {
            root    /usr/share/nginx/www/Site3;
    }

    # pass the PHP scripts to FastCGI server
    location ~ /Site3/.+\.php$ {
            allow 127.0.0.1;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            #we are directly using the $request_filename as its a single php script
            fastcgi_param SCRIPT_FILENAME $request_filename;
    }

此博客的更多详细信息, http: //programmersjunk.blogspot.com/2013/11/nginx-multiple-sites-in-subdirectories.html

于 2013-11-09T04:57:31.243 回答