最近在搞一个前端工程,需要搭在服务器上,所以搞了一个nginx,作为服务器。首选需要在linux安装nginx。
安装之前,先检查一下是否已经安装了nginx:
find -name nginx
如果系统已经安装了nginx,可以通过以下命令卸载,卸载可能会遇到问题,Google上比较全。
apt-get remove nginx
从官网上下载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的安装目录
先执行./configure后别急着往下执行、看看配置不是有有错了、如果不看清楚的话、执行make肯定会出问题、如果迩在make的时候看到出现
./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
安装完以后,再次执行./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文件内容,修改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;
浏览器访问:
以上就是整个的安装教程。