栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Nginx + Node.js + PHP

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx + Node.js + PHP

Nginx允许非常灵活的请求路由。我会告诉你一种设置方法

  • 传递给node.js后端的默认路由
  • 另一条传递给php-fpm后端的路由
  • 传递给典型apache + mod_php后端的替代路由
  • 在nginx机器上有js,图像,css和其他文件?直接从Nginx以最快的方式为他们提供服务

我喜欢,并且我认为这是大多数发行版的默认安装布局,

conf.d
vhosts.d
带有
active
available
文件夹。因此,我只需删除符号链接即可轻松禁用虚拟主机或配置文件。

/etc     nginx.conf     vhosts.d/          active          available     conf.d/          active          available

/etc/nginx.conf

# should be 1 per CPU core    worker_processes        2;error_log    /var/log/nginx/error.log;# I have this off because in our case traffic is not monitored with nginx and I don't want disks to be flooded with google bot requests :)access_log   off;pid          /var/run/nginx.pid;events {        # max clients = worker_processes * worker_connections        worker_connections      1024;        # depends on your architecture, see http://wiki.nginx.org/EventsModule#use        use          epoll;}http {        client_max_body_size    15m;        include      mime.types;        default_type text/html;        sendfile     on;        keepalive_timeout       15;        # enable gzip compression        gzip         on;        gzip_comp_level         6;        gzip_types   text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml application/json;        gzip_http_version       1.0;        # Include conf.d files        include conf.d/active/*.conf;        # include vhost.d files        include vhosts.d/active/*.conf;}

/etc/nginx/vhosts.d/available/default.conf

说我们静态文件的文档根是

/srv/www/vhosts/static/htdocs

server {    server_name _;    listen      80;    root        /srv/www/vhosts/static/htdocs;    # if a file does not exist in the specified root and nothing else is definded, we want to serve the request via node.js    try_files   $uri    @nodejs;    # may want to specify some additional configuration for static files    location ~ .(js|css|png|gif|jpg)    {         expires 30d;    }    location @nodejs    {         # say node.js is listening on port 1234, same host       proxy_pass  127.0.0.1:1234;         break;    }    # just for fun or because this is another application, we serve a subdirectory via apache on another server, also on the other server it's not /phpmyadmin but /tools/phpMyAdmin    location /phpmyadmin {         rewrite /phpmyadmin(.*)$   /tools/phpMyAdmin$1;         proxy_pass      10.0.1.21:80;         break;    }    # files with .php extension should be passed to the php-fpm backend, socket connection because it's on the same and we can save up the whole tcp overhead    location ~.php$    {         fastcgi_pass unix:/var/run/php-fpm.sock;         include /etc/nginx/fastcgi_params;         break;    }}

创建一个符号链接以激活默认虚拟主机

ln -s /etc/nginx/vhosts.d/available/default.conf /etc/nginx/vhosts.d/active/./etc/init.d/nginx restart

看看nginx配置语言多么简单直观?我只是喜欢它:)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417997.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号