- nginx下載下傳
下載下傳位址1:
http://nginx.org/download/
下載下傳位址2:
http://nginx.org/en/download.html
下載下傳位址3:
百度網盤連結:https://pan.baidu.com/s/1UChnaF2bMLr06hA6p6Yzpg
提取碼:hy74
- 建立目錄,上傳nginx.tar.tz
mkdir /home/nginx
Centos7 安裝配置nginx詳解 - 解壓nginx
進入nginx安裝包所在目錄:
cd /home/nginx
解壓:
tar -zxvf nginx-1.18.0.tar.gz
- 配置ssl等
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
如果 -bash: ./configure: 權限不夠 chmod +x configure
如果出現 checking for OS
+ Linux 3.10.0-1127.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
安裝gcc yum install gcc-c++
安裝PCRE yum install -y pcre pcre-devel
安裝zlib yum install -y zlib zlib-devel
安裝openssl yum install -y openssl openssl-devel
安裝之後再次配置 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
- 編譯并安裝
編譯:
make
安裝:
make install
或編譯并安裝:
make && make install
- 啟動
進入nginx啟動目錄:
cd /usr/local/nginx/sbin
啟動:
./nginx
- 通路測試:ip:端口号(預設80),出現下圖說明安裝成功:
Centos7 安裝配置nginx詳解 - 修改配置
vim /usr/local/nginx/conf/nginx.conf
如圖所示(預設配置):可配置https證書、上傳下載下傳大小、靜态資源通路、監聽等
Centos7 安裝配置nginx詳解 發達的 - 退出儲存,并重新開機
重載配置生效:
./nginx -s reload
或停止再啟動生效:
./sbin/nginx -s stop && ./sbin/nginx
- 檢視
ps -ef | grep nginx
Centos7 安裝配置nginx詳解 - nginx.conf詳細配置:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
##############################https證書####################################
#listen 443 ssl;
#keepalive_timeout 100;
#ssl on;
#ssl_certificate /usr/local/nginx/crt/www.xxxx.com_chain.crt;
#ssl_certificate_key /usr/local/nginx/crt/www.xxxx.com_key.key;
#ssl_session_timeout 5m;
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_prefer_server_ciphers on;
###############################https證書###################################
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#預設通路頁面
location / {
root html;
index index.html index.htm;
}
#監聽代理别名
location /yepay {
proxy_pass http://www.xxx.com:8081/;
}
#配置靜态資源通路
location /image/ {
root /usr/local/nginx/resource/;
autoindex on; #打開浏覽通路功能
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}