nginx服务器搭建

Nginx 是一个高性能的HTTP和反向代理服务器

首先可以确定一下自己要用的工具Xshell或者是Activator来链接远程服务器,选择哪个看自己的喜好喽~
1.输入自己的ip地址,用户名和密码远程链接
2.可以先配置一下依赖环境
gcc-c++
yum install gcc-c++
zlib
yum install -y zlib zlib-devel
openssl
yum install -y openssl openssl-devel
3.下载nginx的安装包并解压

我这里用的是1.18.0版本,也可在此自行下载需要的版本http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.18.0.tar.gz

tar -zxvf xxxxx.tar.gz
4.配置,先进到nginx-1.18.0目录下,然后进行配置
cd  nginx-1.18.0

./configure
5.编译/安装
make
make install
6.启动nginx
./nginx
7.另附几个常用的命令

运行nginx

./nginx

停止nginx(快速关闭)

./nginx -s stop

退出nginx(优雅正常关闭)

./nginx -s quit

重启nginx

./nginx -s relaod

查看进程

ps -ef|grep nginx

查看nginx版本

nginx -v
8.如果端口80被占用,可在配置文件中修改
cd /nginx
cd conf
vim nginx.conf

在http中的server中的 listen 80; //可在此修改端口

#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;
    #underscores_in_headers on;
    #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;
    underscores_in_headers on;

    server {
        listen       80;  //可在此修改端口
        server_name  X.XXX.XXX.XX;  //服务器的ip地址
		以下省略......

vim 进入命令模式,修改按键盘上的a(本人习惯,也可按a或o)进入输入模式(也称编辑模式);
然后修改内容;
修改完成后可保存退出:先按键盘上的Esc键,然后shift 加 : 输入:wq保存退出。

9.检查nginx配置是否成功
nginx -t

出现 …is ok 即为配置正确

10.设置开机启动

在/etc/rc.local中增加一行/usr/local/nginx/sbin/nginx即可

	vim /etc/rc.local
	/usr/local/nginx/sbin/nginx
11.设置执行权限:
chmod  755 rc.local
12.在浏览器输入ip即可看到Welcome to nginx的界面

✧✧✧完结撒花(~ ̄▽ ̄)~ ✧✧✧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值