CentOS7 安裝 Nginx
Nginx是一個(gè)高性能的Web服務(wù)器軟件凹蜂。它是一個(gè)比Apache HTTP服務(wù)器更靈活和輕量級的程序。
安裝
- 安裝epel源
EPEL (Extra Packages for Enterprise Linux窟勃,企業(yè)版Linux的額外軟件包) 是Fedora小組維護(hù)的一個(gè)軟件倉庫項(xiàng)目,為RHEL/CentOS提供他們默認(rèn)不提供的軟件包。這個(gè)源兼容RHEL及像CentOS和Scientific Linux這樣的衍生版本贸典。
我們可以很容易地通過yum命令從EPEL源上獲取上萬個(gè)在CentOS自帶源上沒有的軟件拓劝。EPEL提供的軟件包大多基于其對應(yīng)的Fedora軟件包棕诵,不會(huì)與企業(yè)版Linux發(fā)行版本的軟件發(fā)生沖突或替換其文件。
yum install epel-release
#安裝完成之后可以通過下面的命令查看
yum repolist
#可以看到多了一個(gè)
#Extra Packages for Enterprise Linux 7 - x86_64
- 安裝Nginx
yum install nginx
- 啟動(dòng)Nginx
systemctl start nginx
如果運(yùn)行防火墻凿将,請運(yùn)行以下命令以允許HTTP和HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
- 訪問
在瀏覽器中訪問
http://server_domain_name_or_IP/
http://192.168.1.213/
能看Nginx的默認(rèn)頁
- 系統(tǒng)啟動(dòng)時(shí)啟動(dòng)Nginx
systemctl enable nginx
- 配置
默認(rèn)服務(wù)器根
默認(rèn)服務(wù)器根目錄是 /usr/share/nginx/html 放置在其中的文件將在您的Web服務(wù)器上提供訪問校套。
此位置在Nginx附帶的默認(rèn)服務(wù)器塊配置文件中指定,該文件位于 /etc/nginx/conf.d/default.conf
服務(wù)器塊配置
可以通過在/etc/nginx/conf.d中創(chuàng)建新的配置文件來添加任何附加的服務(wù)器塊(在Apache中稱為虛擬主機(jī))牧抵。當(dāng)Nginx啟動(dòng)時(shí)笛匙,將加載該目錄中以.conf結(jié)尾的文件。
Nginx全局配置
主要的Nginx配置文件位于/etc/nginx/nginx.conf犀变。在這里您可以更改設(shè)置妹孙,如運(yùn)行Nginx守護(hù)進(jìn)程的用戶,以及當(dāng)Nginx運(yùn)行時(shí)生成的工作進(jìn)程數(shù)等获枝。
忘了之前是怎么安裝的了 ~~
服務(wù)名是:
nginx16-nginx.service
配置文件位于:
/opt/rh/nginx16/root/etc/nginx/nginx.conf
內(nèi)容:
error_log /var/log/nginx16/error.log;
......
access_log /var/log/nginx16/access.log main;
......
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /opt/rh/nginx16/root/var/log/nginx/host.access.log main;
location / {
#root /opt/rh/nginx16/root/usr/share/nginx/html;
#index index.html index.htm;
root /data/bdmi/html;
index login.html index.html index.htm;
}
location /baseUrl {
rewrite ^.+baseUrl/?(.*)$ /bdmi-biz/$1 break;
include uwsgi_params;
proxy_pass http://192.168.1.92:8080;
proxy_set_header Cookie $http_cookie;
proxy_cookie_path /bdmi-biz /;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
......
關(guān)于SELINUX問題
首先查看本機(jī)SELinux的開啟狀態(tài)蠢正,如果SELinux status參數(shù)為enabled即為開啟狀態(tài)
/usr/sbin/ sestatus -v
或者使用getenforce命令檢查
SELinux can be run in enforcing, permissive, or disabled mode
To add httpd_t to the list of permissive domains, run this command:
# semanage permissive -a httpd_t
To delete httpd_t from the list of permissive domains, run:
# semanage permissive -d httpd_t
To set the mode globally to enforcing, run:
# setenforce 1