导航:首页 > 程序命令 > centos7nginx命令

centos7nginx命令

发布时间:2022-09-22 23:26:13

① centos 安装完Nginx后,为什么访问不了

【解决方法】

本地试下端口是否可访问telnet 192.168.4.155 80;

CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙。

firewall:
systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动

在centos下尝试使用$curl http://127.0.0.1命令访问nginx。确定是否可以访问。

② centos7怎么编译安装nginx

安装环境为:最小化安装的centos7,关闭seliunx。
最小化安装centos:
关闭selinux
sed –i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

开始安装nginx1.7.8
创建群组
groupadd www
创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g www -M www
#下载最新版nginx
wget -C http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxvf nginx-1.7.8.tar.gz
#编译基本能运行的nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
make install

如果有错误提示:
./configure: error: C compiler cc is not found
解决方法:
yum install gcc gcc-c++

如果有错误提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre=<path> option.
解决方法:
yum install pcre-devel

如果有错误提示:
./configure: error: SSL moles require the OpenSSL library.
You can either do not enable the moles, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解决方法:
yum install openssl-devel

以上错误提示依次解决后:再一次的运行
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
meke install

编译参数解释:
#指定运行权限的用户
--user=www
#指定运行的权限用户组
--group=www
#指定安装路径
--prefix=/usr/local/nginx
#支持nginx状态查询
--with-http_stub_status_mole
#开启ssl支持
--with-http_ssl_mole
#开启GZIP功能
--with-http_gzip_static_mole

因此要顺利的通过nginx编译安装必须安装的依赖关系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2、在 centos7 中为nginx的启动、重启、重载配置添加脚本
nginx直接启动的方法:
/usr/local/nginx/sbin/nginx

但是不是很方便,因此使用下面的脚本来控制nginx的启动关闭重载更加合理一些。
编辑文件:vim /usr/lib/systemd/system/nginx.service 添加下面的脚本,注意路径 !
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl的一些使用方法:
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable xxx.service #开机运行服务
systemctl disable xxx.service #取消开机运行
systemctl start xxx.service #启动服务
systemctl stop xxx.service #停止服务
systemctl restart xxx.service #重启服务
systemctl reload xxx.service #重新加载服务配置文件
systemctl status xxx.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

因此,添加上面脚本后,centos7 中操作nginx的方法有
systemctl is-enabled nginx.service #查询nginx是否开机启动
systemctl enable nginx.service #开机运行nginx
systemctl disable nginx.service #取消开机运行nginx
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重启nginx
systemctl reload nginx.service #重新加载nginx配置文件
systemctl status nginx.service #查询nginx运行状态
systemctl --failed #显示启动失败的服务

③ 如何在 centos 7/cpanel 服务器上配置 nginx 反向代理

注:本配置环境在CentOS下实现,其他方法请参考官方帮助文件

一、安装Nginx软件
Nginx官方网站:http://nginx.org
我们使用yum安装(配置和升级方便),需要配置官方的yum源,Nginx官方源配置提供的配置方法如下:

1.创建一个更新源
#vim /etc/yum.repos.d/nginx.repo

2.加入如下内容:
[nginx]
name=nginx repo baseurl=http://nginx.org/packages/OS/EOSRELEAS/$basearch/
gpgcheck=0
enabled=1

3.把上面蓝色字段换成的操作系统类型,比如rhel或者centos,把绿色部分替换成发行的主版本号,比如“5” 或者 “6”, 分别代表 5.x 或 6.x 对应的版本。

其他版本的系统(Debian/Ubuntu)也可以参考nginx官方的方法配置(英文内容)。

4.配置完以上三部,就可以开始用我们熟悉的yum命令安装nginx了(默认安装最新的nginx稳定发行版本)。
#yum install nginx

5.安装完毕看看都生成了哪些文件,配置文件都放在哪里
#rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/example_ssl.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/rc.d/init.d/nginx
/etc/sysconfig/nginx
/usr/sbin/nginx
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx

以上是我安装完的配置文件位置,安装的版本是1.4.2版本(查看版本:nginx -v) ,如下图:

6.检查是否安装成功
启动nginx服务,输入服务器ip访问是否能打开默认网站:
#service nginx restart

如果nginx服务启动成功,但打不开网站,排除如果不是网络问题,可能是因为iptables,iptables开放80端口即可:
#vim /etc/sysconfig/iptables
加入:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 如下图:

二、配置文件
1.由上面的步骤,我们看到配置文件放置在/etc/nginx/目录下:
主要配置文件:/etc/nginx/nginx.conf 内容如下图
扩展配置文件:/etc/nginx/conf.d/*.conf

图中的主配置文件的末尾,加载所有扩展配置文件里面以.conf结尾的文件。所以我们不要修改主要配置文件(不需要修改),用户配置都放到了/etc/nginx/conf.d/目录下,里面默认有两个配置文件,一个普通的配置,一个是ssl配置。

2.为一个域名配置一个文件(文件名任意,以.conf结尾即可)
#cd /etc/nginx/conf.d/
#vim www.test.com.conf
把内容修改如下:
---------------------------------------------------------------------------
server {
listen 80;
server_name www.test.com;

charset utf8;
access_log /var/log/nginx/www.test.com.access.log main;

location / {
proxy_pass http://192.168.1.20:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
---------------------------------------------------------------------------
如图:

3.重启nginx服务,检查配置文件并生效(nginx -t)
#service nginx restart

4.如果没出意外,你应该已经成功实现Nginx反向代理服务了!

三、其他帮助
1.帮助命令

2.官方帮助文档:http://nginx.org/en/docs/

④ 如何在 CentOS 7 用 cPanel 配置 Nginx 反向代理

第一步: 安装 EPEL 库
root@server1 [/usr]# yum -y install epel-release
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
* EA4: 66.23.237.210
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
epel-release noarch 7-5 extras 14 k

第二步: 安装 nDeploy 的 CentOS RPM 库
可以安装 nDeploy 的 CentOS RPM 库来安装我们所需的 nDeploy Web 类软件和 Nginx 插件
root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm
Loaded plugins: fastestmirror, tsflags, universal-hooks
nDeploy-release-centos-1.0-1.noarch.rpm | 1.7 kB 00:00:00
Examining /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm: nDeploy-release-centos-1.0-1.noarch
Marking /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package nDeploy-release-centos.noarch 0:1.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110

第三步:安装 nDeploy 和 Nginx nDeploy 插件
root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeploy
Loaded plugins: fastestmirror, tsflags, universal-hooks
epel/x86_64/metalink | 9.9 kB 00:00:00
epel | 4.3 kB 00:00:00
ndeploy | 2.9 kB 00:00:00
(1/4): ndeploy/7/x86_64/primary_db | 14 kB 00:00:00
(2/4): epel/x86_64/group_gz | 169 kB 00:00:00
(3/4): epel/x86_64/primary_db | 3.7 MB 00:00:02

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy noarch 2.0-11.el7 ndeploy 80 k
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
Installing for dependencies:
PyYAML x86_64 3.10-11.el7 base 153 k
libevent x86_64 2.0.21-4.el7 base 214 k
memcached x86_64 1.4.15-9.el7 base 84 k
python-inotify noarch 0.9.4-4.el7 base 49 k
python-lxml x86_64 3.2.1-4.el7 base 758 k

Transaction Summary
========================================================================================
Install 2 Packages (+5 Dependent packages)

通过以上这些步骤,我们完成了在我们的服务器上 Nginx 插件的安装。现在我们可以配置 Nginx 作为反向代理和为已有的 cPanel 用户账户创建虚拟主机,为此我们可以运行如下脚本。
第四步:启动 Nginx 作为默认的前端 Web 服务器,并创建默认的配置文件
root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enable
Modifying apache http and https port in cpanel

httpd restarted successfully.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_watcher.service to /usr/lib/systemd/system/ndeploy_watcher.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_backends.service to /usr/lib/systemd/system/ndeploy_backends.service.
ConfGen:: saheetha
ConfGen:: satest

你可以看到这个脚本将修改 Apache 的端口从 80 到另一个端口来让 Nginx 作为前端 Web 服务器,并为现有的 cPanel 用户创建虚拟主机配置文件。一旦完成,确认 Apache 和 Nginx 的状态。
Apache 状态:
root@server1 [/var/run/httpd]# systemctl status httpd
● httpd.service - Apache Web Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-01-18 06:34:23 UTC; 12s ago
Process: 25606 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 24760 (httpd)
CGroup: /system.slice/httpd.service
‣ 24760 /usr/local/apache/bin/httpd -k start

Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Starting Apache Web Server...
Jan 18 06:34:23 server1.centos7-test.com apachectl[25606]: httpd (pid 24760) already running
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.

Nginx 状态:
root@server1 [~]# systemctl status nginx
● nginx.service - nginx-nDeploy - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2016-01-17 17:18:29 UTC; 13h ago
Docs: http://nginx.org/en/docs/
Main PID: 3833 (nginx)
CGroup: /system.slice/nginx.service
├─ 3833 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─25473 nginx: worker process
├─25474 nginx: worker process
└─25475 nginx: cache manager process

Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Starting nginx-nDeploy - high performance web server...
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Started nginx-nDeploy - high performance web server.

Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听 http 端口 9999 和 https 端口 4430。请看他们的情况:
root@server1 [/usr/local/src]# netstat -plan | grep httpd
tcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 17270/httpd
tcp6 0 0 :::4430 :::* LISTEN 17270/httpd
tcp6 0 0 :::9999 :::* LISTEN 17270/httpd

root@server1 [/usr/local/src]# netstat -plan | grep nginx
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx: master
tcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx: master

为已有用户创建的虚拟主机的配置文件在 “/etc/nginx/sites-enabled”。 这个文件路径包含了 Nginx 主要配置文件。
root@server1 [/etc/nginx/sites-enabled]# ll | grep .conf
-rw-r--r-- 1 root root 311 Jan 17 09:02 saheetha.com.conf
-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf

一个域名的示例虚拟主机:
server {

listen 45.79.183.73:80;
#CPIPVSIX:80;

# ServerNames
server_name saheetha.com www.saheetha.com;
access_log /usr/local/apache/domlogs/saheetha.com main;
access_log /usr/local/apache/domlogs/saheetha.com-bytes_log bytes_log;

include /etc/nginx/sites-enabled/saheetha.com.include;

}

我们可以启动浏览器查看网站来确定 Web 服务器的工作状态。安装后,请阅读服务器上的 web 服务信息。
root@server1 [/home]# ip a | grep -i eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 45.79.183.73/24 brd 45.79.183.255 scope global dynamic eth0
root@server1 [/home]# nginx -v
nginx version: nginx/1.8.0

Nginx 将会为任何最新在 cPanel 中创建的账户创建虚拟主机。通过这些简单的的步骤,我们能够在一台 CentOS 7 / cPanel 的服务器上配置 Nginx 作为反向代理。
Nginx 作为反向代理的优势
便于安装和配置。
效率高、性能好。
防止 Ddos 攻击。
支持使用 .htaccess 作为 php 的重写规则。

⑤ 如何安装nginx

nginx
windows版
v1.13.3免费版http://www.ddooo.com/softdown/29113.htm
nginx
windows安装配置方法
第一步、安装方法
一、下载好后,把nginx
windows版软件解压到c盘根目录。
二、双击nginx.exe图标,可见黑窗口一闪而过,启动完毕。
三、按下win+R快捷键,输入cmd打开命令行。
四、命令行到nginx目录,输入nginx启动。(注,此方式命令行窗口无任何提示,且被锁定)
五、打开浏览器,输入http://127.0.0.1,如果看到下图片则安装成功。
六、以后启动软件直接双击图标即可。
七、启动后,默认情况下(无修改配置),可见到有两个nginx的进程,一个是master
process,一个是worker
processes测试。
第二步、配置方法
配置目标:能正常运行PHP脚本程序
大部分情况下,我们需要修改的配置文件只有一个,那就是nginx.conf,该文件位于conf目录下。具体配置项目为:
1.
server_tokens
off;
出于安全方面的考虑,最好是隐藏nginx版本号信息
2.
listen
8088;
8088为监听端口,根据需要可以填写其它端口号
3.
server_name
localhost;
localhost为服务器访问名称,也就是我们在浏览器里输入的那个url地址
4.
charset
utf-8;
字符集编码
5.
工作目录
将如下配置
修改为:
root
定义了工作空间,也就是我们php项目所在的目录。
加入index.php是为了让nginx能够识别php脚本,否则,在访问php文件时,会出现直接下载的情况。
6.
整合php
将location
~
\.php配置部分的注释全部去掉,最终配置如下:
注意这里面的$document_root变量,它对应的内容就是root参数值,如果我们没有定义root参数或者把root注释掉,在访问php的时候,页面上就会出现No
input
file
specified.提示。
7.
启动php-cgi
打开cmd命令窗口,切换到php的安装目录,执行php-cgi
-b
127.0.0.1:9000,即可启动php-cgi,启动完成后,cmd窗口切勿关闭,否则php-cgi也会被关掉的。
特别提醒:只有在开启php-cgi的情况下,nginx才能正常访问php。
8.
重启nginx
打开cmd命令窗口,切换到nginx所在目录,执行nginx
-s
reload即可重启nginx。其它相关nginx相关命令如下:
启动:start
nginx
停止:nginx
-s
stop
退出:nginx
-s
quit

⑥ nginx如何配置https的301重定向,以及nginx的检查重启命令是什么

首先需要配置好SSL证书,网上有很多相关教程,具体不多说了,

配置好SSL证书后,(Nginx配置)会有两个文件,一个以.crt结尾,一个以.key结尾的。

网上有很多配置http跳转到https得到教程,都是下面rewrite的方法,这里不建议使用rewrite规则跳转,容易出现重定向次数过多的问题

rewrite ^(.*)$ https://$host$1 permanent;

我们可以使用return来实现

return 301 https://www.000000.com$request_uri;

Nginx文件更改好要在重启下才会生效,否则还会变成原来的内容,这里建议重启前先检查下配置文件是否争取:

首先找到Nginx的所在目录,目录下有sbin文件,进入到sbin文件下执行以下命令:

执行: ./nginx -t

如果出现……ok和……success语句,则正面文件配置正确

执行: ./nginx -s reload

这个时候不会出现任何提示,Nginx的301重定向就已经完成了。

注意事项:进入sbin目录下执行命令,前面一定要加上./

⑦ centos7重启nginx

如果你是以服务模式启动的nginx,重启nginx的命令为:systemctl restart nginx.service如果你是通过命令行启动的nginx,重启命令为ngnx -s restart 望采纳

⑧ centos7怎么查看已经安装nginx

如果你nginx是rpm包安装的,直接用如下命令:
nginx
-V
如果你是源码包编译安装,假如你的安装路径是/usr/local/nginx,那么你可以使用:
/usr/local/nginx/sbin/nginx
-V
注意是大写的V,这样你就可以看到nginx已经加载的模块了。

阅读全文

与centos7nginx命令相关的资料

热点内容
江苏金税盘测试服务器地址是什么 浏览:607
螺杆式压缩冷凝机组 浏览:297
p在单片机里什么意思 浏览:25
linuxwireshark使用教程 浏览:656
手机访问阿里服务器地址 浏览:678
程序员可以干什么 浏览:70
绩效考核权重分配算法 浏览:524
android应用logo 浏览:898
光遇安卓服墓土商店什么时候开 浏览:566
月收益翻倍的源码 浏览:638
asop源码放在哪里 浏览:989
电脑服务器密码怎么找 浏览:574
jdp转换pdf 浏览:749
把pdf导入iphone 浏览:508
米哈游租赁的云服务器是哪个 浏览:524
android直接打电话 浏览:1018
ubuntu停止命令 浏览:285
cnc攻丝编程 浏览:870
换个手机号码app怎么注册 浏览:321
怎么下载小猴口算app 浏览:117