nginx简单配置php服务(多个)
nginx简单配置php服务(多个)
摘要:大部分网站开发语言都要运行在服务器,比如主流的nginx、apache等等,部署服务器环境对于大部分人来说是比较陌生和复杂的,其实搞懂了之后是很简单易用的。今天就记录下部署php+nginx。
系统:mac、linux
1、安装好php和nginx程序,并运行。
2、找到nginx.conf文件,默认在/etc/nginx目录下,如果找不到用一下命令查询
sudo find / -name nginx.conf
3、修改nginx.conf文件
默认的nginx.conf配置
#user nobody;
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 localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#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_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$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;#}}# 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;# }#}include servers/*;
}
把server下的这段#号去掉并修改即可,将 PHP 脚本传递给在 127.0.0.1:9000 上侦听的 FastCGI 服务器
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
访问 localhost
参数参考:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径
fastcgi_param QUERY_STRING $query_string; #请求的参数;如?app=123
fastcgi_param REQUEST_METHOD $request_method; #请求的动作(GET,POST)
fastcgi_param CONTENT_TYPE $content_type; #请求头中的Content-Type字段
fastcgi_param CONTENT_LENGTH $content_length; #请求头中的Content-length字段。fastcgi_param SCRIPT_NAME $fastcgi_script_name; #脚本名称
fastcgi_param REQUEST_URI $request_uri; #请求的地址不带参数
fastcgi_param DOCUMENT_URI $document_uri; #与$uri相同。
fastcgi_param DOCUMENT_ROOT $document_root; #网站的根目录。在server配置中root指令中指定的值
fastcgi_param SERVER_PROTOCOL $server_protocol; #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。 fastcgi_param GATEWAY_INTERFACE CGI/1.1;#cgi 版本
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;#nginx 版本号,可修改、隐藏fastcgi_param REMOTE_ADDR $remote_addr; #客户端IP
fastcgi_param REMOTE_PORT $remote_port; #客户端端口
fastcgi_param SERVER_ADDR $server_addr; #服务器IP地址
fastcgi_param SERVER_PORT $server_port; #服务器端口
fastcgi_param SERVER_NAME $server_name; #服务器名,域名在server配置中指定的server_name
配置多个服务:
nginx.conf文件有一行
include servers/*;
代表会读取servers文件夹下的所有配置文件,没有可以自己加上,并创建文件夹,servers文件夹下创建一个站点配置文件site1.conf。
server {listen 80;#端口server_name site1.com;#你的站点域名/iproot /data/site1/public; #你的站点目录,绝对路径即可index index.php index.html index.htm;#charset koi8-r;#access_log logs/host.access.log main;location / {try_files $uri $uri/ /index.php?$query_string;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
分享不易,点赞收藏以免需要时找不到了!
nginx简单配置php服务(多个)相关推荐
- nginx动态配置及服务发现那些事
标题, <闲聊nginx动态配置及服务发现的那些事> - 这次的准备闲聊关于nginx服务发现的话题, 按照我以往写文章的性子,估计会迁移一些主题. 毕竟单纯聊nginx和动态服务发 ...
- 前后端联调的一般步骤和Nginx简单配置
前后端联调的一般步骤 1.创建前端工程(这里创建的是vue-cli项目) 2.编写后端登录业务 3.替换页面元素为自己需要的,比如图标,标题之类的 4.编写前端页面Vue组件 5.编写跳转到组件的路由 ...
- 本地spa应用的nginx简单配置
最近碰到一个棘手的问题,开发打包都没问题,发到线上页面不出来报错:Uncaught SyntaxError: Invalid or unexpected token,为了方便调试于是使用nginx起本 ...
- Nginx安装配置与服务搭建
Nginx概述 Nginx(发音同engine x)是一款由俄罗斯程序员Igor Sysoev所开发轻量级的网页服务器.反向代理服务器以及电子邮件(IMAP/POP3)代理服务器.起初是供俄国大型的门 ...
- 网络安全学习篇35_第二阶段_lnmp、Nginx简单配置+安装报错:C compiler cc is not found缺少环境解决、安装php5.3.28
上一篇博客:网络安全学习篇34_第二阶段_apache.mysql等配置+ centOS设置中文输入法 目录 Nginx的简单介绍 Nginx的安装 安装的时候报了一个错:C compiler cc ...
- Nginx简单配置转发
问题分析 一台服务器运行多个项目的时候会遇到这样的问题:如果使用同一个tomcat来启动不同项目的话,项目之间会相互影响:如果用多个tomcat运行项目,那么在访问项目的时候又不能都使用80端口,还要 ...
- 关于https工程的nginx简单配置
1.下载域名的ssl证书,由于项目部署在阿里云上,就用了阿里推荐的赛门铁克,用Let's Encrypt的也不错. 2.nginx的配置如下: worker_processes 8;error_log ...
- 【菜鸟dei学习】Nginx简单配置:负载均衡与动静分离
反向代理 首先我们来说说***正向代理***.比如你要访问资源A,但是访问不到,你可以通过访问资源B,再通过它你访问到资源A,这即是正向代理.可能多个用户都通过资源B访问资源A,它隐藏了客户端的访问身 ...
- nginx 简单配置
https的配置方法 #这个是接口文档的---------------------------------- server { #侦听80端口 listen 80; #定义使用 www.nginx.c ...
最新文章
- 车模换几代了,电池什么时候换?
- 【深度学习】Dropout、正反向传播、计算图等的介绍和实现(Pytorch)
- sql如何实现明细账_SQL 如何实现动态的行列转置
- MSP432P401R TI Drivers 库函数学习笔记(一)导入工程模板
- 上河南星海科技_揭秘丨赣江新区网红打卡点,为你按下科技快进键!
- 数据库名、实例名、数据库域名、全局数据库名、服务名 我也迷糊了
- 解读Scorm(0):标准
- Thingsboard 3.1.0 - REST API
- Java旅游管理系统本科生毕业设计任务书
- android mp3 lrc歌词文件utf-8歌词显示为乱码,Android访问Tomcat错误以及mp3player项目乱码问题解决...
- obj模型 vue_Vue各种各样的模型库 Cornucopia 3D for Vue
- ANU COMP1100 Lab1简介
- 通过Safari浏览器获取iOS设备UDID(设备唯一标识符)
- Java——使用多线程模拟真实高并发业务并保证安全性(一)
- scanf来代替gets
- MyBatis源码简单分析
- no cortex-m sw device found 问题解决【转】
- 在家兼职网上开淘宝店具体步骤是啥?
- 如何隐藏任务栏图标小结(zz)
- cannot import name evaluate