更新部分:
需要注意的是这里配置php的通信连接为SOCKET,并非常用的PHP开启的9000端口,因此配置为fastcgi_pass unix:/usr/local/php/var/run/www.sock;
[root@VM-0-6-centos conf]# cat nginx.conf
user nginx;
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 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.liuyuanshan.top;
#charset koi8-r;
#paccess_log logs/host.access.log main;
#paccess_log logs/laravel.access.log main;
root html;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_index index.php;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/usr/local/php/var/run/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
location /status {
auth_basic "http://106.52.36.65";
auth_basic_user_file /usr/local/nginx/html/pass.db;
stub_status;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
server {
listen 80;
server_name laravel.liuyuanshan.top;
root html/laravel;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/usr/local/php/var/run/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
问题处理
参考文章:
https://blog.csdn.net/hithedy/article/details/86693393
盘查nginx与php之间的解析出现问题,或者是php或者nginx端口为开启
https://juejin.im/post/6847902219812274190
有机会要弄一个反向代理分发
具体的php与nginx配置请看本人博客里的搭建
cd /root/nginx/conf/conf.d
vim runoob-test-php.conf
runoob-test-php.conf文件内容,其实就是子域名对应目录就行
server {
listen 80;
server_name www.liuyuanshan.top;
location / {
#proxy_pass http://106.52.36.65:80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name message.liuyuanshan.top;
location / {
root /usr/share/nginx/html/message/;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/message/$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name wordpress.liuyuanshan.top;
location / {
root /usr/share/nginx/html/wordpress/;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name;
include fastcgi_params;
}
}
重启docker的nginx容器
docker restart ngixn