In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to deploy php projects under nginx. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something through the detailed introduction of this article.
How to deploy php project under nginx: 1. Install nginx and php-fpm;2. Find the configuration file of nginx server;3. Specify the deployment location of php project;4. Put all kinds of configured server conf in sites-enabled.
Operating environment: linux 5.9.8 system, nginx version 1.9, Dell G3 computer.
How to deploy PHP project under nginx?
Deploying php projects on nginx servers
Nginx itself cannot process PHP pages, it is just a web server, when receiving the request, if it is a PHP request, it is forwarded to the PHP interpreter through a reverse proxy, and the result is returned to the client. So you need to install nginx and php-fpm or another php interpreter on your server.
After installing nginx and php-fpm, find the configuration file of nginx server
[root@test24266conf]# ps -ef | grep nginx.confroot 31441 1 0 2018 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
In this file, specify the deployment location of the php project, that is, modify the root directory of the file specified by root under the server field.
Many hairstyle versions, there is no server field in nginx.conf, this is for management convenience, some precompiled versions of the distribution, nginx.conf http section will have two sentences include conf.d/*.conf; include sites-enabled/* or only one include
sites-enabled/*.conf; This way you can put various configured server conf in sites-enabled, such as
[root@test24266conf]# ll sites-enabled/-rw-r--r--1 root root 603 103 2017 captcha443.conf-rw-r--r--1 root root 287 9 1 2017 commrisk.conf-rw-r--r--1 root root 194 129 2016 imagerotate.conf-rw-r--r--1 root root 402 9 2 2016 msgqapi.conf-rw-r--r--1 root root 295 102 2017 pointriskapi.conf-rw-r--r--1 root root 290 6 2 2017 risktrade.conf-rw-r--r--1 root root 309 814 2017 rotateapi.conf-rw-r--r--1 root root 313 100 2016 watchdog.conf[root@test24266conf]# In this way, each.conf file can correspond to a virtual host. Check a configuration file, such as [root@test24266conf]# cat sites-enabled/pointriskapi.confserver{ listen 8013; server_name point.risk.api; index index.php; #Default access files root /var/www/pointriskapi/hosts; access_log on;#When requesting php files from a website, reverse proxy to php-fpm location ~ .*\. php?$ { include fastcgi.conf; } location = /favicon.ico { log_not_found off; access_log off; } }[root@test24266conf]#
We put the php project file under this/var/www/pointriskapi/hosts path, such as
[root@test24266hosts]# ll -rw-r--r-- 1 apache apache 339 102 2017risk_point.php[root@test24266hosts]# pwd/var/www/pointriskapi/hosts
There is generally no need to restart Nginx and php-fpm. You can now access http://ip:8013/risk_point.php from the client.
So how does nginx forward requests to PHP interpreters via reverse proxy? We noticed that there was a paragraph in the server field
location ~ .*\. php?$ { include fastcgi.conf; #Load fastcgi module of nginx }
This paragraph specifies who handles.php files. We look at the factcgi.conf file in the nginx.conf sibling directory, such as
[root@test24266 conf]# cat fastcgi.conffastcgi_pass 127.0.0.1:9000;#fastcgi_pass unix:/tmp/phpcgi.socket;fastcgi_indexindex.php; access_log /var/log/httpd/access_log main; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name; # PHPonly, required if PHP was built with --enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;[root@test24266conf]#
Fastcgi_pass indicates the IP address and port on which the fastcgi process listens, i.e. nginx will forward the request to this socket. So we need to specify the same socket in the php-fpm configuration file. Start Php-fpm listening, view
[root@test24266~]# netstat -anp | grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3719/php-fpm
In nginx and php-fpm mode, the complete request and response flow is as follows:
The client requests a.php file on the server.
2, Nginx discovery is dynamic resources need to route to the specified root directory
3. Load fast-cgi module of nginx
Fact-cgi listening 127.0.0.1: 9000 (default socket)
5. php-fpm receives the request and enables the worker process to process the request.
6, php-fpm process request, return to nginx
7. nginx returns the results to the browser via http
The above content is how to deploy php projects under nginx. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.