# 源码安装的nginx,目录/application/nginx-1.8.1
useradd coosh
su - coosh
# 以下为nginx.conf配置文件的内容,注意该文件是放在coosh的家目录下
# 由于该配置文件不是在nginx安装目录中,所以里面的目录路径要全换成绝对路径
cat >nginx.conf <
worker_processes 1;
error_log /home/coosh/error.log;
pid /home/coosh/nginx.pid;
events {
worker_connections 1024;
}
http {
include /application/nginx-1.8.1/conf/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_types text/css text/xml text/plain application/Javascript;
gzip_min_length 1k;
gzip_comp_level 5;
gzip_vary on;
server {
listen 8080;
access_log off;
# 我的网站目录是在家目录下的website目录中
root /home/coosh/website;
location / {
root /home/coosh/website;
index index.php;
}
location ~ \.php$ {
#由于9000端口已经被另一个php-fpm占用了&#xff0c;所以另起了一个9001
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
#这里的$document_root取值是server块里的root
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /application/nginx-1.8.1/conf/fastcgi.conf;
}
}
}
EOF
#测试一下该配置文件
/application/nginx/sbin/nginx -c /home/coosh/nginx.conf -t
#通常会提示没有权限访问/application/nginx-1.8.1/logs/error.log&#xff0c;这确实很奇怪&#xff0c;因为在配置文件里命名是配了error_log参数&#xff0c;但仍提示这个路径&#xff0c;解决的方法是用root给这个文件配上所有人可读写。
logout
chmod 666 /application/nginx-1.8.1/logs/error.log
# 回到coosh用户下
su - coosh
/application/nginx/sbin/nginx -c /home/coosh/nginx.conf -t
# 如无意外&#xff0c;会提示OK和successful