Nginx安裝
1 安裝依賴包
//一鍵安裝四個依賴
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2 下載并解壓安裝包
//創建一個檔案夾
cd /usr/local
mkdir nginx
cd nginx
//下載tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
3 安裝nginx
//進入nginx目錄
cd /usr/local/nginx
//進入目錄
cd nginx-1.13.7
//執行命令
./configure
//執行make命令
make
//執行make install命令
make install
4 配置nginx.conf
// 打開組態檔
vim /usr/local/nginx/conf/nginx.conf
配置server
server {
listen 3001;
server_name localhost;
root /srv/realbim/client/dist;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$/index.html last;
}
location /api {
proxy_pass http://192.168.1.224:81;
}
#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;
#}
}
5 啟動nginx
/usr/local/nginx/sbin/nginx -s reload
如果報錯:nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed
則運行:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
再次啟動即可!
6 查看nginx行程是否啟動
ps -ef | grep nginx
7 常用命令
安裝完成一般常用命令
進入安裝目錄中,
cd /usr/local/nginx/sbin
啟動,關閉,重啟,命令:
./nginx 啟動
./nginx -s stop 關閉
./nginx -s reload 重啟
8 訪問
ping 確認ip是否通
telnet 確認埠是否通
systemctl stop firewalld 停止防火墻
user root; nginx.conf用戶改為root
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/232255.html
標籤:其他
