Linux CentOS 7 yum安裝啟動配置 nginx
- 一 下載下傳源
- 二 安裝
- 三 啟動
- 四 配置
-
- 1 開機自啟
- 2 配置代理
- 第一次寫部落格,如有問題請指正。
一 下載下傳源
Nginx不是預設的yum源,我們使用官網的 yum 源。
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
二 安裝
yum install nginx
三 啟動
systemctl start nginx
四 配置
1 開機自啟
systemctl enable nginx
2 配置代理
Nginx配置檔案在 /etc/nginx/nginx.conf
vim /etc/nginx/nginx.conf
user nginx; // 如果配置代理自定義靜态目錄需改為 user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
== 等号裡的代碼就是自定義的代理配置
server {
listen 80 default_server; //目标端口
listen [::]:80 default_server; //目标端口
server_name www.xxx.com //域名配置
root /data/www; //靜态目錄解析位址(例如 官網。。。)
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8080; //端口代理配置,我這裡是把8080端口代理到80端口(端口優先級大于靜态解析位址,在配置端口代理的情況下,靜态目錄位址不生效)
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
==
}