CentOS 配置Nginx服务器并上传网站到服务器

Web服务器

Nginx:高性能,高并发

Apache:多平台、安全、流行

Tomcat:多用于Java做jsp解析

 

下面配置Nginx

Nginx官网中的安装方式

 

一般不推荐,我们直接在CentOS中直接安装

先查看nginx是否存在

nginx -V

下载nginx

yum install nginx

如果没有找到nginx包,则找到nginx包,然后再去安装Nginx

yum install epel-release

然后再查看Nginx版本

nginx -V nginx 
version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

修改nginx的权限

  将user nginx 改为user root

  http -> server -> location /

默认位置在 /etc/nginx 配置文件为nginx.conf

[root@root src]# cd /etc/nginx
[root@root nginx]# ls
conf.d        fastcgi.conf.default    koi-utf     mime.types.default  scgi_params          uwsgi_params.default
default.d     fastcgi_params          koi-win     nginx.conf          scgi_params.default  win-utf
fastcgi.conf  fastcgi_params.default  mime.types  nginx.conf.default  uwsgi_params

如果上面方法没找到,可以使用 nginx -t 找到配置文件地址

nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

使用vim去修改配置文件,如果没有vim 通过yum install vim 来下载

vim nginx.conf    //使用来打开配置文件

 

root为网站路径 index是输入ip之后会给我们显示哪个网页

然后在/root下建立www文件夹

mkdir www

git bush 可以在本地项目处直接getbush 使用scp命令

scp -r local_dir user@ip:/remote_dir

然后使用 scp 命令看是否存在,如果没有,使用 yum install openssh-client来安装scp

local_dir:本地文件  user:linux用户一般为root  remote_dir:为服务器上的路径,上面配置的是root/www

然后远程连接到服务器 cd /root/www/ ls看是否上传进来了

[root@root ~]# cd /root/www 
[root@root www]# ls 

然后查看nginx是否启动 ps -ef | grep nginx

ps -ef | grep nginx 
root 12745 12625 0 10:29 pts/1 00:00:00 vim nginx.conf 
root 12924 12905 0 11:56 pts/3 00:00:00 grep --color=auto nginx

停止nginx服务的命令:

nginx -s stop

开启nginx服务的命令:

nginx nginx -s reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值