由于本人水平有限,以下记录仅作参考。
下面贴出我的一份正常运行的nginx服务器虚拟机配置。/usr/local/nginx/conf/vhost/www.xsll.com.conf
1 server { 2 listen 80; #虚拟主机监听端口 3 server_name www.xsll.com; #虚拟主机名称 4 5 #charset koi8-r; 6 #access_log /var/log/nginx/log/host.access.log main; 7 8 root /home/wwwroot/default/discuz/upload; #你的项目目录 9 index index.php index.html index.htm; #默认寻找的文件 10 11 location / { 12 try_files $uri $uri/ =404; 13 if (!-e $request_filename){ 14 rewrite ^/(.*)?$ /$1.php?last; 15 } 16 } 17 18 error_page 404 /404.html; 19 20 # redirect server error pages to the static page /50x.html 21 # 22 error_page 500 502 503 504 /50x.html; 23 location = /50x.html { 24 root /usr/share/nginx/html; 25 } 26 27 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 28 # 29 #location ~ \.php$ { 30 # proxy_pass http://127.0.0.1; 31 #} 32 33 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 34 # 35 location ~ \.php$ { 36 #root html; 37 try_files $uri = 404; 38 fastcgi_pass unix:/tmp/php-cgi.sock; #这一行很重要,路径要与PHP配置文件中的监听路径相同,但前面要加unix:/ 39 fastcgi_index index.php; 40 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 41 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 42 include fastcgi_params; 43 } 44 45 # deny access to .htaccess files, if Apache‘s document root 46 # concurs with nginx‘s one 47 # 48 #location ~ /\.ht { 49 # deny all; 50 #} 51 }
下面我贴出我的php的配置文件/user/local/php/etc/php-fpm.conf
1 [global] 2 pid = /usr/local/php/var/run/php-fpm.pid 3 error_log = /usr/local/php/var/log/php-fpm.log 4 log_level = notice 5 6 [www] 7 listen = /tmp/php-cgi.sock 8 listen.backlog = -1 9 listen.allowed_clients = 127.0.0.1 10 listen.owner = www 11 listen.group = www 12 listen.mode = 0666 13 user = www 14 group = www 15 pm = dynamic 16 pm.max_children = 10 17 pm.start_servers = 2 18 pm.min_spare_servers = 1 19 pm.max_spare_servers = 6 20 request_terminate_timeout = 100 21 request_slowlog_timeout = 0 22 slowlog = var/log/slow.log
可以看到在虚拟主机配置的38行:fastcgi_pass unix:/tmp/php-cgi.sock;这个路径正式php配置文件中第7行:listen = /tmp/php-cgi.sock;这样nginx虚拟机就支持了PHP程序解析了。
时间: 2024-10-19 17:09:17