Nic*_*rin 5 php permissions nginx
我在设置本地 nginx 环境时遇到问题。我在网上阅读了无数教程,一切似乎都让我的大脑有点混乱。
操作系统:OSX 10.11.4 El Capitan Nginx:1.8.1 PHP-FPM:5.5.31
我的网站根目录目前的文件目录如下:
/webserver
/webverver/phpinfo.php
/webserver/example
/webserver/example/index.php
Run Code Online (Sandbox Code Playgroud)
我可以使用curl 或在Web 浏览器中访问本地主机来访问默认的“欢迎使用Nginx”页面。如果我随后浏览,我会获得文件的索引,但 PHP 文件将尝试下载而不是执行。如果我尝试访问我创建的示例站点local.example.com(我已将其添加到我的主机文件中),那么我会使用curl 得到 403 Forbidden header return,并使用网络浏览器得到一个漂亮、简单的“Access Denied”。
我对文件权限和目录所有权不太了解,有人可以建议我应该如何配置所有内容吗?建议我运行以下命令,但到目前为止它没有任何改变:
sudo chmod -R 755 /Users/nickcorin/webserver
除了“信号启动”日志之外,我的错误日志中没有任何日志。
这是我目前的配置:
nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root /Users/nickcorin/webserver;
autoindex on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
Run Code Online (Sandbox Code Playgroud)
servers/example
upstream php {
server 127.0.0.1:9000;
}
server {
listen 80;
root /Users/nickcorin/webserver/example;
server_name local.example.com;
index index.php index.html index.htm;
autoindex on;
location ~ \.php$ {
try_files $uri $uri/ /index.php?$args ;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
** 编辑 - NGINX 文件夹权限和进程所有者 **
我ls -la在日志文件夹上运行/usr/local/var/nginx,结果如下:
drwxr-xr-x 4 nickcorin admin 136 Apr 20 23:53 .
drwxr-xr-x 5 nickcorin admin 170 Apr 20 21:47 ..
-rw-r--r-- 1 root admin 4718 Apr 21 08:06 access.log
-rw-r--r-- 1 nickcorin admin 480 Apr 21 10:28 error.log
Run Code Online (Sandbox Code Playgroud)
这是我的网络服务器根目录上的结果:
drwxr-xr-x 4 nickcorin staff 136 Apr 22 12:23 .
drwx-----x+ 54 nickcorin staff 1836 Apr 22 10:01 ..
drwxr-xr-x 3 nickcorin staff 102 Apr 20 22:14 example
-rw-r--r--@ 1 nickcorin staff 23 Apr 19 11:58 info.php
Run Code Online (Sandbox Code Playgroud)
这是以下结果ps aux | grep nginx:
root 756 0.0 0.0 2466616 480 ?? Ss 12:24PM 0:00.00 nginx: master process nginx
nickcorin 759 0.0 0.0 2445080 820 s000 S+ 12:24PM 0:00.00 grep nginx
nobody 757 0.0 0.0 2475832 1044 ?? S 12:24PM 0:00.00 nginx: worker process
Run Code Online (Sandbox Code Playgroud)
** 编辑 #2 - 虚拟主机配置文件 **
我设法解决了我的问题,现在一切似乎进展顺利。我必须将我的虚拟主机配置文件编辑为:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name local.example.com;
root /Users/nickcorin/webserver/example;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
我还用以下两行修复了我的权限:
sudo chown -R nickcorin /Users/nickcorin/webserver (Web Server Root)
sudo chmod 755 /Users/nickcorin/webserver/example (Virtual Host Root)
Run Code Online (Sandbox Code Playgroud)
感谢所有帮助我解决这个问题的人:)
我遇到的问题是我的虚拟主机的配置文件和我的网络服务器根目录的权限。这些是我当前的工作配置设置,供其他遇到类似问题的人使用:
nginx.conf
user yourusername staff;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log warn;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root /Users/yourusername/webserver;
autoindex on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
Run Code Online (Sandbox Code Playgroud)
servers/example
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name local.example.com;
root /Users/yourusername/webserver/example;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
一旦这些设置正确,我就运行这些命令来修复网络服务器中的权限错误:
sudo chown -R yourusername /Users/yourusername/webserver
sudo chmod 755 /Users/yourusername/webserver/example
Run Code Online (Sandbox Code Playgroud)
不要忘记添加127.0.0.1 local.example.com到您的主机文件中。
| 归档时间: |
|
| 查看次数: |
17756 次 |
| 最近记录: |