我想在我的 Ubuntu 10.04 32 位 Linode VPS 上运行 nginx。
sudo chown -R www-data:www-data /var/www
sudo chmod -R 775 /var/www
sudo add-apt-repository ppa:nginx/development
sudo apt-get update
sudo apt-get install nginx
制作一个 nginx 虚拟主机:
mkdir -p /var/www/example.com/{public,logs}
sudo nano /etc/nginx/sites-available/example.com
并写了以下
server {
listen 80;
server_name www.example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
server {
listen 80;
server_name example.com;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;
location / {
root /var/www/example.com/public/;
index index.html;
}
}
然后我启用了虚拟主机 example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
sudo /etc/init.d/nginx restart
我将 index.html 放入/var/www/example.com/public
并从浏览器中输入 www.example.com URL。然后我得到了关注
403 Forbidden
nginx/0.8.53
tail /var/log/nginx/error.log
给出以下错误
*38 directory index of "/var/www/" is forbidden, client: 88.224.1.128, server: localhost, request: "GET / HTTP/1.1", host: www.example.com
我重做
sudo chown -R www-data:www-data /var/www
sudo chmod -R 775 /var/www
但它给出了同样的错误。
和猫 /etc/nginx/nginx.cnf
user www-data;
worker_processes 1;
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;
# As per: http://wiki.nginx.org/NginxHttpGzipModule#gzip_disable starting
# with 0.7.63
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
如果我将 index.html 放在 /var/www/ 中,那么我可以看到 html 文件,但任何将其放在 /var/www/example.com/public 下的尝试都会失败。我查看了文件和文件夹权限,它们都属于 www-data 并且可读(775)
我该怎么做才能使 nginx 工作?谢谢