Ubuntu16.04 安裝配置nginx,實(shí)現(xiàn)多項(xiàng)目管理、負(fù)載均衡
1、配置nginx代理
配置apache的監(jiān)聽端口為8080, /etc/apache2/ports.conf
Listen 8080
配置 /etc/nginx/sites-available 復(fù)制
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/80
進(jìn)入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; } }
參數(shù)說明:
root:根目錄
proxy_pass: 代理
一、實(shí)現(xiàn)多項(xiàng)目管理
1.apache監(jiān)聽端口,/etc/apache2/ports.conf
vi /etc/apache2/ports.conf
#然后添加監(jiān)聽端口
Listen 8081
2.復(fù)制 000-default.conf配置虛擬機(jī)
sudo cp 000-default.conf 8081.conf
進(jìn)入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代理
進(jìn)入 /etc/nginx/sites-available文件,復(fù)制80
sudo cp /etc/nginx/sites-available/80 /etc/nginx/sites-available/81
修改81文件的內(nèi)容如下:
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應(yīng)該為項(xiàng)目根目錄,也就是說,在該目錄下應(yīng)該有入口文件;proxy_pass 的8081也應(yīng)該跟apache的端口一致
3、負(fù)載均衡
功能完善中。。。

浙公網(wǎng)安備 33010602011771號