search
HomeBackend DevelopmentPHP Tutorialmacos - PHP Nginx environment configured on mac. When accessing php files, downloading occurs instead of executing php files.

<code>vim /usr/local/etc/nginx/sites-available/default
</code>
<code>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;
}
</code>
<code>/usr/local/etc/nginx/nginx.conf
</code>
<code>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/*;
}

</code>

/usr/local/etc/nginx/sites-available/default This file configures port 80. Why can’t port 80 be accessed, but can access port 8080?

When accessing port 80, a 404 error cannot be found

Reply content:

<code>vim /usr/local/etc/nginx/sites-available/default
</code>
<code>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;
}
</code>
<code>/usr/local/etc/nginx/nginx.conf
</code>
<code>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/*;
}

</code>

/usr/local/etc/nginx/sites-available/default This file configures port 80. Why can’t port 80 be accessed, but can access port 8080?

When accessing port 80, a 404 error cannot be found

First you need a php-fpm to run php, and then configure it to the correct location

Refer to my conf:

<code>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;
  }
}</code>

If you have any questions, you can search for the keyword:

nginx connects to php-fpm

The one I provide is the http method. You can switch to the more efficient socket method. Keyword: socket nginx php-fpm

    404 error you can check the error.log log
  • Have you found that php-fpm and nginx are not combined?
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何使用php-fpm进行高性能调优如何使用php-fpm进行高性能调优Jul 08, 2023 am 11:30 AM

如何使用php-fpm进行高性能调优PHP是一种非常流行的服务器端脚本语言,广泛用于开发网页应用和动态网站。然而,随着访问量的增加,PHP应用程序的性能可能会受到影响。为了解决这个问题,我们可以使用php-fpm(FastCGIProcessManager)来进行高性能调优。本文将介绍如何使用php-fpm来提升PHP应用程序的性能,并提供代码示例。一、

如何使用PHP-FPM优化提高WooCommerce应用的性能如何使用PHP-FPM优化提高WooCommerce应用的性能Oct 05, 2023 am 08:24 AM

如何使用PHP-FPM优化提高WooCommerce应用的性能概述WooCommerce是一个非常流行的电子商务插件,用于在WordPress网站上创建和管理在线商店。然而,随着商店的增长和流量的增加,WooCommerce应用可能会变得缓慢和不稳定。为了解决这个问题,我们可以使用PHP-FPM来优化和提高WooCommerce应用的性能。什么是PHP-FP

利用php-fpm连接池提升数据库访问性能利用php-fpm连接池提升数据库访问性能Jul 07, 2023 am 09:24 AM

利用php-fpm连接池提升数据库访问性能概述:在Web开发中,数据库的访问是非常频繁且耗时的操作之一。传统的方法是每次数据库操作都新建一个数据库连接,使用完毕后再关闭连接。这种方式会造成数据库连接的频繁建立和关闭,增加了系统的开销。为了解决这个问题,可以利用php-fpm连接池技术来提升数据库访问性能。连接池的原理:连接池是一种缓存技术,将一定数量的数据库

php-fpm调优方法详解php-fpm调优方法详解Jul 08, 2023 pm 04:31 PM

PHP-FPM是一种常用的PHP进程管理器,用于提供更好的PHP性能和稳定性。然而,在高负载环境下,PHP-FPM的默认配置可能无法满足需求,因此我们需要对其进行调优。本文将详细介绍PHP-FPM的调优方法,并给出一些代码示例。一、增加进程数默认情况下,PHP-FPM只启动少量的进程来处理请求。在高负载环境下,我们可以通过增加进程数来提高PHP-FPM的并发

什么是php-fpm?如何进行优化来提升性能?什么是php-fpm?如何进行优化来提升性能?May 13, 2022 pm 07:56 PM

什么是php-fpm?下面本篇带大家了解一下php-fpm,介绍一下优化 php-fpm 时我们到底要优化什么,希望对大家有所帮助!

ubuntu没有php-fpm怎么办ubuntu没有php-fpm怎么办Feb 03, 2023 am 10:51 AM

ubuntu没有php-fpm的解决办法:1、通过执行“sudo apt-get”命令添加php的源地址;2、查看有没有php7的包;3、通过“sudo apt-get install”命令安装PHP;4、修改配置监听9000端口来处理nginx的请求;5、通过“sudo service php7.2-fpm start”启动“php7.2-fpm”即可。

利用php-fpm进程管理实现负载均衡利用php-fpm进程管理实现负载均衡Jul 09, 2023 pm 01:07 PM

利用php-fpm进程管理实现负载均衡随着互联网应用的日益复杂和用户量的增加,负载均衡成为一个不可或缺的技术。负载均衡的目标是将流量分配到多个服务器上,以提高系统的稳定性和性能。在PHP应用中,php-fpm(PHPFastCGIProcessManager)是一种常见的进程管理工具,可以被用于实现负载均衡,并且提供了灵活的配置选项。本文将介绍如何利用

php-fpm性能监控与调优策略php-fpm性能监控与调优策略Jul 07, 2023 am 08:39 AM

php-fpm性能监控与调优策略引言:随着互联网的发展,PHP作为一种高效的服务器端脚本语言,被广泛应用于Web开发领域。而php-fpm作为php运行环境的一种解决方案,具有较高的并发处理能力。然而,在高并发的情况下,php-fpm会面临性能瓶颈的问题。本文将介绍php-fpm的性能监控与调优策略,旨在提高php-fpm的性能和稳定性。一、php-fpm性

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version