【发布时间】:2018-03-31 20:06:02
【问题描述】:
如何在 nginx (1.12.2) 上为 php 设置绝对 docroot?
<?php
die(print_r(getcwd(), TRUE));
?>
给我 /var/www/mydomain.com
我想将 mydomain.com 设置为 docroot,然后能够使用 '/' ex.
include '/css/style.css';
现在我必须使用
include '/var/www/mydomain.com/css/style.css';
我的 nginx 配置
server {
listen 80;
server_name mydomain.com;
root /var/www/mydomain.com/;
index index.php index.html index.htm;
error_page 404 /404.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/mydomain.com$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location / {
try_files $uri $uri/ =404;
}
}
将所有站点文件设置在公共或 html 文件夹 (/var/www/mydomain.com/public) 中是否有什么好的做法?
【问题讨论】:
-
-
只需使用
__DIR__获取您所在文件的绝对路径,并从中导航。 -
我不想使用
__DIR__当我有主机时我可以使用'/' -
@Widziks 你的问题不清楚!你到底想要什么?