mac nginx 解析php文件,macos - mac 配置的PHP Nginx 环境 访问php文件出现下载而不是执行php文件...

vim /usr/local/etc/nginx/sites-available/default

server {

listen 80;

server_name localhost;

root /var/www/;

access_log /usr/local/var/logs/nginx/default.access.log main;

location / {

index index.html index.htm index.php;

autoindex on;

include /usr/local/etc/nginx/conf.d/php-fpm;

}

location = /info {

allow 127.0.0.1;

deny all;

rewrite (.*) /.info.php;

}

error_page 404 /404.html;

error_page 403 /403.html;

}

/usr/local/etc/nginx/nginx.conf

worker_processes 1;

error_log /usr/local/var/logs/nginx/error.log debug;

pid /usr/local/var/run/nginx.pid;

events {

worker_connections 256;

}

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 /usr/local/var/logs/access.log main;

sendfile on;

keepalive_timeout 65;

port_in_redirect off;

include /usr/local/etc/nginx/sites-enabled/*;

}

/usr/local/etc/nginx/sites-available/default 这个文件配置的是80端口,为啥80端口不能访问, 但是8080 可以访问

80 端口访问都是出现404 错误找不到

回复内容:

vim /usr/local/etc/nginx/sites-available/default

server {

listen 80;

server_name localhost;

root /var/www/;

access_log /usr/local/var/logs/nginx/default.access.log main;

location / {

index index.html index.htm index.php;

autoindex on;

include /usr/local/etc/nginx/conf.d/php-fpm;

}

location = /info {

allow 127.0.0.1;

deny all;

rewrite (.*) /.info.php;

}

error_page 404 /404.html;

error_page 403 /403.html;

}

/usr/local/etc/nginx/nginx.conf

worker_processes 1;

error_log /usr/local/var/logs/nginx/error.log debug;

pid /usr/local/var/run/nginx.pid;

events {

worker_connections 256;

}

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 /usr/local/var/logs/access.log main;

sendfile on;

keepalive_timeout 65;

port_in_redirect off;

include /usr/local/etc/nginx/sites-enabled/*;

}

/usr/local/etc/nginx/sites-available/default 这个文件配置的是80端口,为啥80端口不能访问, 但是8080 可以访问

80 端口访问都是出现404 错误找不到

首先你需要一个 php-fpm 来跑 php,然后还要把它配置到正确的位置

参考我的 conf:

server {

listen 80;

server_name xxxxxx;

index index.php;

root /usr/www/web-sites/xxxxxx;

error_log /var/log/nginx/xxxxxx.xxx.error.log;

access_log /var/log/nginx/xxxxxx.xxx.access.log;

location / {

try_files $uri /index.php$is_args$args;

}

location ~ ^/.+\.php(/|$) {

fastcgi_pass php_fpm:9000;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {

expires 1d;

}

}

有问题可以搜索关键字:nginx 连接 php-fpm

我提供的这种是 http 方式,你可以换用效率更高的 socket 方式,关键字:socket nginx php-fpm

404错误你可以看看error.log日志

你有没有发现php-fpm和nginx没有结合?

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了在 macOS 上搭建 PHP 开发环境,你可以按照以下步骤进行操作: 1. 安装 Homebrew:Homebrew 是 macOS 上一个常用的包管理器。打开终端并输入以下命令安装 Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装 PHP:使用 Homebrew 安装 PHP。在终端输入以下命令: ``` brew install php ``` 3. 配置 PHP:默认情况下,Homebrew 会将 PHP 安装在 `/usr/local/etc/php` 目录下。你可以根据需要进行配置更改。 4. 安装一个 Web 服务器:你可以选择安装 Apache 或 Nginx 作为 Web 服务器。下面是安装 Apache 的步骤: - 安装 Apache: ``` brew install httpd ``` - 配置 Apache:编辑 `/usr/local/etc/httpd/httpd.conf` 文件进行必要的配置更改,如修改网站根目录等。 - 启动 Apache: ``` sudo apachectl start ``` - 在浏览器输入 `http://localhost`,如果看到 "It works!" 的页面,则说明 Apache 已经成功安装并运行。 5. 安装数据库:如果你需要使用数据库,可以选择安装 MySQL 或 PostgreSQL。使用以下命令安装 MySQL: ``` brew install mysql ``` - 启动 MySQL: ``` brew services start mysql ``` - 设置 MySQL 根密码: ``` mysql_secure_installation ``` 6. 安装开发工具:你可以选择安装一个集成开发环境(IDE)或文本编辑器,如 Visual Studio Code、PhpStorm、Sublime Text 等。 这样,你的 macOS PHP 开发环境就搭建完成了。你可以在配置文件进行进一步的定制和调整,以适应你的开发需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值