一:
# setenforce 0 # systemctl stop firewalld //盡量使用國(guó)內(nèi)源 # yum install -y epel-release # cd /etc/yum.repos.d/ # yum install -y nginx # killall httpd //有Apache服務(wù)先關(guān) # systemctl restart nginx # ps aux | grep nginx
或
二:nginx源下載
# cd /etc/yum.repos.d/ # rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # vim nginx.repo # yum -y install nginx # systemctl restart nginx
在/etc/nginx/conf.d/目錄下存放著多個(gè)配置文件,這些配置文件在Nginx運(yùn)行時(shí)加載到主配置項(xiàng)目中(類似虛擬機(jī))
Nginx是通過(guò)php-fpm來(lái)通訊的,所以需要監(jiān)聽9000端口
在這個(gè)目錄下生成一個(gè)自己的配置文件例如admin.conf
# vim /etc/nginx/conf.d/admin.conf server { listen 80; server_name www.test.com admin.test.com; index index.html inex.htm index.php; root /var/www/card/public; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } ? location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } ? # yum install -y php-fpm # vim /etc/php-fpm.d/www.conf user = nginx group = nginx # cd /var/www # mkdir -p card/public # cd card/public # vim php_info.php <?php echo "php解析正常" ?> # systemctl restart php-fpm # lsof -i:9000 # systemctl restart nginx # setenforce 0 # systemctl stop firewalld //192.168.1.2/php_info.php
192.168.1.3 web端
192.168.1.2 代理服務(wù)器(www.test.com)
# cd /etc/nginx/conf.d/ # mv admin.conf admin.conf.bak # rm -rf default.conf.rpmsave # vim default.conf upstream test{ server 192.168.1.3 weight=1 #權(quán)重越高訪問次數(shù)越多 } server { listen 80; server_name www.test.com; access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://test; #這里可直接寫IP地址進(jìn)行配置,如果需要配置負(fù)載均衡,可以使用http://test和upstream名稱一致 } } ? # systemctl restart nginx # //web端 # systemctl stop firewalld # setenforce 0
聯(lián)系客服