Ubuntu16.04 安装配置nginx,实现多项目管理、负载均衡

 
1、配置nginx代理
配置apache的监听端口为8080, /etc/apache2/ports.conf
Listen 8080
 
配置  /etc/nginx/sites-available 复制
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/80
 
进入80文件更改如下:
server {
         listen 80;
         listen [::]:80;
 
         server_name 127.0.0.1;
 
         root /var/www/test/;
         index index.html,index.php;
 
         location / {
                proxy_pass  http://localhost:8080;
                try_files $uri $uri/ =404;
         }
}
参数说明:
root:根目录
proxy_pass: 代理
 
 
一、实现多项目管理
 
1.apache监听端口,/etc/apache2/ports.conf
vi /etc/apache2/ports.conf

#然后添加监听端口
Listen
8081

 

    2.复制 000-default.conf配置虚拟机
sudo cp 000-default.conf 8081.conf
进入8081.conf配置如下:
<VirtualHost *:8081>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/CRM
        #ServerName localhost
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Include conf-available/serve-cgi-bin.conf
 
         <Directory /var/www/CRM>
                #Options FollowSymLinks
                #Options Indexes FollowSymLinks MultiViews 
                #AllowOverride None
                DirectoryIndex index.html index.htm index.php
         </Directory>
 </VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
查看代码
 
    3.配置完成还得讲8081.conf文件链接到 sites-enabled 目录下
sudo ln -s //etc/nginx/sites-available/80 /etc/nginx/sites-available/81
 
    4.配置nginx代理
 
进入 /etc/nginx/sites-available文件,复制80
sudo cp /etc/nginx/sites-available/80 /etc/nginx/sites-available/81 
 
修改81文件的内容如下:
server {
        listen 81;
        listen [::]:81;

        server_name 127.0.0.1;
 
        root /var/www/CRM/;
        index index.html,index.php;
 
        location / {
                 proxy_pass  http://localhost:8081;
                 try_files $uri $uri/ =404;
        }
 }
查看代码
这里需要注意,root应该为项目根目录,也就是说,在该目录下应该有入口文件;proxy_pass 的8081也应该跟apache的端口一致
 
 
3、负载均衡
 
 
 
功能完善中。。。
 
 
posted @ 2021-07-26 14:47  我若亦如风  阅读(224)  评论(0编辑  收藏  举报