一、準備工作
1.1 更新系統安裝包列表
# apt update
1.2 必須軟件包
下面都是編譯nginx必須的,提前安裝好。
# apt install gcc make
# apt install libpcre3 libpcre3-dev //【正則表達式庫】 官網http://www.pcre.org/
# apt install openssl libssl-dev //【openssl庫】 官網https://www.openssl.org/
# apt install zlib1g-dev
1.3 創建需要使用的目錄
創建目錄source和web,分別用來放源碼和編譯後的文件。
# mkdir /source/
# mkdir /web/
二、安裝nginx
2.1 安裝nginx
[官方網站] http://nginx.org/
命令流程:
# cd /source/
# wget http://nginx.org/download/nginx-1.13.5.tar.gz
# tar -zxf nginx-1.13.5.tar.gz
# cd nginx-1.13.5
# ./configure –prefix=/web/nginx –with-http_ssl_module
# make && make install
–with-http_ssl_module //打開https
三、配置nginx
3.1 打開nginx.conf
vim nginx.conf
3.2 支持php。在server里加入
複製代碼
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
複製代碼
3.3 支持asp.net。在server里加入
複製代碼
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
複製代碼
3.4 防火牆添加80、443端口(可選,需要外網訪問的)
# firewall-cmd –zone=public –add-port=80/tcp –permanent //–permanent永久生效,沒有此參數重啟後失效
# firewall-cmd –reload //重新載入
附、常用命令
nginx常用命令
# ln -s /web/nginx/sbin/nginx /usr/local/bin //快捷方式
# /web/nginx/sbin/nginx //啟動nginx
# /web/nginx/sbin/nginx -s reload //重啟nginx
# /web/nginx/sbin/nginx -s stop //關閉nginx
以下文章點擊率最高
Loading…