最近在搞一個前端工程纲辽,需要搭在服務器上榆综,所以搞了一個nginx绿店,作為服務器吉懊。首選需要在linux安裝nginx。
安裝之前惯吕,先檢查一下是否已經(jīng)安裝了nginx:
find -name nginx
如果系統(tǒng)已經(jīng)安裝了nginx惕它,可以通過以下命令卸載,卸載可能會遇到問題废登,Google上比較全淹魄。
apt-get remove nginx
從官網(wǎng)上下載nginx下載到公共賬戶appops的soft文件夾下:
cd soft
wget http://nginx.org/download/nginx-1.12.0.tar.gz
解壓nginx壓縮包:
tar -zxvf nginx-1.12.0.tar.gz
解壓以后會生成一個nginx-1.12.0目錄,進入該目錄:
cd nginx-1.12.0
接下來安裝nginx堡距,可以使用--prefix指定安裝目錄甲锡,這里使用默認目錄
./configure $默認安裝在/usr/local/nginx
make
make install
如果沒有報錯,順利完成后羽戒,最好看一下nginx的安裝目錄
先執(zhí)行./configure后別急著往下執(zhí)行缤沦、看看配置不是有有錯了、如果不看清楚的話易稠、執(zhí)行make肯定會出問題缸废、如果邇在make的時候看到出現(xiàn)
./configure: error: the HTTP rewrite module requires the PCRE library
解決方法:
apt-get update
apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl-dev
安裝完以后,再次執(zhí)行./configure命令
./configure
make
make install
這樣就安裝成功了。
可以通過whereis nginx查看nginx的安裝路徑
whereis nginx
然后校驗是否安裝成功
/usr/local/nginx/sbin/nginx -v
啟動和重啟Nginx
啟動:
/usr/local/nginx/sbin/nginx
重啟
/usr/local/nginx/sbin/nginx -s reload
停止啟動
/usr/local/nginx/sbin/nginx -s stop
停止進程
查詢nginx主進程號 ps -ef | grep nginx
停止進程 kill -QUIT 主進程號
快速停止 kill -TERM 主進程號
強制停止
pkill -9 nginx
通過瀏覽器訪問企量,再次確認是否安裝成功测萎;
首先需要修改nginx.conf文件,進入/usr/local/nginx/conf
cd /usr/local/nginx/conf
vim nginx.conf
nginx.conf文件內(nèi)容届巩,修改server_name為你服務器的機器ip:
#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 {
listen 80;
server_name XX.XX.XXX.200;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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;
# }
#}
}
修改完配置以后硅瞧,重啟nginx;
瀏覽器訪問:
以上就是整個的安裝教程恕汇。