安装配置nginx

一、在线安装nginx 

The steps in this tutorial require the user to have root privileges. You can see how to set that up by following steps 3 and 4 in the Initial Server Setup with CentOS 7 tutorial.

Step One—Add Nginx Repository
To add the CentOS 7 EPEL repository, open terminal and use the following command:
sudo yum install epel-release
Step Two—Install Nginx
Now that the Nginx repository is installed on your server, install Nginx using the following yum command:
sudo yum install nginx
After you answer yes to the prompt, Nginx will finish installing on your virtual private server (VPS).
Step Three—Start Nginx
Nginx does not start on its own. To get Nginx running, type:
sudo systemctl start nginx
If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload



Glad to hear you got it working!
In the future, here's something that might come in useful. You can check the syntax of Nginx's configuration files by running:

• nginx -t -c /etc/nginx/nginx.conf
The error output will give you a hint at what the problem is as well as the line number.


二、nginx 服务器重启命令,关闭

nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:
nginx -s stop  :快速停止nginx
         quit  :完整有序的停止nginx

其他的停止nginx 方式:

ps -ef | grep nginx

kill -QUIT 主进程号     :从容停止Nginx
kill -TERM 主进程号     :快速停止Nginx
pkill -9 nginx          :强制停止Nginx

三、nginx代理配置

upstream my_server {

server10.0.0.2:8080 weight=10;

server10.0.0.2:8080 weight=20;

keepalive2000;

}

server {


listen80;

server_name10.0.0.1;

client_max_body_size1024M;

location /my/ {

proxy_pass http://my_server/;

proxy_set_header Host $host:$server_port;

}}


server 10.0.0.2:8080 ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值