我正在尝试从XAMPP迁移到Nginx from服务器。我曾经使用Xampp运行多个网站,每个web文件夹都位于xampp/htdocs文件夹下。例如,我将以代码http://myserver/site1[code]和代码http://myserver/site2[code]访问站点(yii web站点),它们将从htdocs下的site1和site2文件夹中访问。但我在nginx中设置它时遇到了问题。我已经将根文件夹的默认配置设置为/etc/share/ nginx /www ( site1和site2文件夹在www下),当我使用nginx以同样的方式访问时,网页会给出一个错误,说“没有指定输入文件”。我知道在nginx中设置了多个站点,使用不同的域名和根文件夹,但是可以使用类似于xampp的配置吗?因为我正在我的本地网络上测试它,并且我不想为此设置多个域名。
发布于 2013-11-07 05:48:06
nginx最新版本的配置非常简单。首先,你应该编辑nginx/conf/nginx.conf,并确保你有像include vhosts/*.conf; inside 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添加到您的主机文件中,这样它就可以被本地识别了。
发布于 2021-04-30 04:14:33
这很简单。
删除您的数据库,压缩它们,重新导入它们或使用MySQL根-p BASENAME
然后,只需移动您的默认目录,如/var/www/html,并使用chmod0777 -R /the/path将权限设置为0777或更小,也可以使用chown www-data:www-data -R /the/path,然后重新启动系统。
发布于 2013-11-09 12:57:31
经过一番努力,我终于找到了理想的配置。我知道这不是一个推荐的设置,但这是给我的问题(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
https://stackoverflow.com/questions/19821959
复制相似问题