经过10多个小时的研究,我还没弄清楚为什么这不起作用!我正在尝试将我的localhost移动到我的启用站点的文件夹,该文件夹位于/ etc / nginx / sites-enabled / default中 .
它是来自sites-available文件夹的符号链接 . 使用以下配置时,我使用localhost:8080作为我的地址“无法连接”
nginx.conf(/usr/local/nginx/conf/nginx.conf):
user www-data;
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/sites-enabled/*;
}
sites-available(/ etc / nginx / sites-available / default):
server {
listen 8080;
root /home/myusername/myown/customdirectory;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
如果我将相关信息从nginx.conf的可用站点中提取出来,我可以得到这个工作,我只是想不通为什么它不能这样工作?
谢谢!
3 回答
在
sites-enabled/default
中包括sites-available/default
. 它只需要一行 .在
sites-enabled/default
(新配置版本?):包含路径似乎与包含它的文件相关
见include documentation .
我相信某些版本的nginx允许包含/链接到其他文件,纯粹是通过一条线与包含文件的相对路径 . (至少那是我一直在使用的一些“继承”配置文件中的样子,直到一个新的nginx版本打破它们 . )
在
sites-enabled/default
(旧的配置版本?):似乎include路径是相对于当前文件的
改变自:
至
解决了我的问题
我有同样的问题 . 这是因为我不小心使用了带有符号链接的相对路径 .
你确定你使用了完整的路径,例如: