随身笔记
随身笔记

ubuntu 16.04 nginx+apache组合 nginx反向代理

nginx负责处理静态页面就是html标签,apache负责处理php脚本,对于那些访问量大的网站来说这样的组合是比较高效的。

本博客就是使用这样的组合搭建的。

 

配置方法:

1,在此之前需要安装了lamp环境,可以参考https://sdeno.com/?p=5280

之后修改apache的默认端口为8080,在路径/etc/apache2/ports.conf

 

2,安装nginx服务端sudo apt-get install nginx,nginx负责监听80端口过滤静态请求,然后动态请求即Proxy 到Apache 的8080 端口。Proxy 反向代理的好处是访问的时候,始终就是80端口,来访者不会觉察到有任何的区别。(我安装的版本为nginx/1.10.0)

 

3,配置nginx

安装完成nginx之后测试下是否成功,nginx和apache一样默认web路径都是/var/www/html,

访问:http://localhost/index.nginx-debian.html  看看是否能成功。

进入到目录 /etc/nginx/sites-available/  创建一个文件名为test的文件内容是:

//以下是对php网站的设置

server {
  listen 80;
  access_log /var/www/html/nginx.access.log;
  error_log /var/www/html/nginx.error.log;
  root /var/www/html;
  index index.php index.html;
  server_name www.xgllseo.com xgllseo.com;
  location \ {
    try_files $uri $uri/ index.php/$uri;
  }
  location ~* ^.*\.php$ {
    if (!-f $request_filename) {
       return 404;
    }
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080; (前提要保证https://sdeno.com:8080/这样能正常访问到,也就是要绑定域名和修改端口)
  }
  location ~ /\.(ht|git) {
    deny all;
  }
}



//node.js配置可以是
server{
  listen 80;
  server_name xx.com www.xx.com;
  location /{
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_cache_bypass $http_upgrade;  
  }
  access_log /var/www/node/node.log;
}






//为node.js设置内存缓存
http {
 proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
 proxy_temp_path /var/tmp;
 include mime.types;
 default_type application/octet-stream;
 sendfile on;
 keepalive_timeout 65;
 
 gzip on;
 gzip_comp_level 6;
 gzip_vary on;
 gzip_min_length 1000;
 gzip_proxied any;
 gzip_types text/plain text/htm text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
 gzip_buffers 16 8k;
 
 ssl_certificate /root/www/Nginx/1_www.easynode.cn_bundle.crt;
 ssl_certificate_key /root/www/Nginx/2_www.easynode.cn.key;
 ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK;
 ssl_prefer_server_ciphers on;
 
 upstream silly_face_society_upstream {
 server 127.0.0.1:3011;
 #server 127.0.0.1:61338;
 keepalive 64;
 }
 
 #server {
 # listen 80;
 #listen 443 ssl;
 
 # server_name easynode.cn;
 #return 301 $scheme://www.sillyfacesociety.com$request_uri;
 #}
 
 server {
 listen 80;
 #listen 443 ssl;
 
 server_name www.easynode.cn;
 
 #error_page 502 /errors/502.html;
 
  #if ($scheme = http) { #80端口跳转443
  #   return 301 https://$server_name$request_uri;
  #}
 #location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
 #root /root/www/easynode/public;
 #access_log off;
 #expires max;
 #}
 
location ~ .*\.(woff|eot|svg|ttf|favicon.ico|gif|jpg|jpeg|png|bmp|swf)$
{
#expires 30d;
expires max;
root /root/www/easynode/public; #重点
}

location ~ .*\.(js|css)?$
{
#expires 12h;
expires max;
root /root/www/easynode/public; #重点
}
 
 #location /errors {
 # internal;
 # alias /usr/local/silly_face_society/node/public/errors;
 #}
 
 location / {
 proxy_redirect off;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_set_header Host $http_host;
 proxy_set_header X-NginX-Proxy true;
 proxy_set_header Connection "";
 proxy_http_version 1.1;
 proxy_cache one;
 proxy_cache_key sfs$request_uri$scheme;
 proxy_pass http://silly_face_society_upstream;
 }
 }
}

 

创建软链接

sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test

这时候就会在 sites-enabled目录下看到刚刚的test配置被启动了

sudo /etc/init.d/nginx restart  重启nginx如果OK说明没问题

 

4,配置apache

在/etc/apache2/sites-available/目录下创建名为test.conf的文件内容是:

<VirtualHost *:8080>
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/html
</VirtualHost>

 

创建软链接

sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf

在sites-enabled目录能看到刚刚的test.conf说明也启动成功。

 

接着按照下面顺序执行下

sudo a2ensite test
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 reload

 

5,尝试下是否成功,

在/var/www/html/目录下创建1.php内容为<?php phpinfo();?>的php文件,

访问:http://localhost/1.php 。

如果成功那就完成了。

 

http://www.2cto.com/os/201202/119597.html 

没有标签
首页      ubuntu      ubuntu 16.04 nginx+apache组合 nginx反向代理

随身笔记

ubuntu 16.04 nginx+apache组合 nginx反向代理
nginx负责处理静态页面就是html标签,apache负责处理php脚本,对于那些访问量大的网站来说这样的组合是比较高效的。 本博客就是使用这样的组合搭建的。   配置方法: 1,…
扫描二维码继续阅读
2016-11-05