Nginx安装包下载地址:nginx: download
配置Nginx的安装源
- //一键安装四个依赖
- yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
官网查看nginx的版本号,根据需要通过修改命令下载最新的或自己需要的版本,例如:
wget http://nginx.org/download/nginx-1.23.1.tar.gz
- //创建一个文件夹
- cd /usr/local
- mkdir nginx
- cd nginx
- //下载tar包
- wget http://nginx.org/download/nginx-1.23.1.tar.gz
- tar -xvf nginx-1.23.1.tar.gz
- //进入nginx目录
- cd /usr/local/nginx/nginx-1.23.1
- //执行命令 考虑到后续安装ssl证书 添加两个模块
- ./configure --with-http_stub_status_module --with-http_ssl_module
- //执行make命令
- make && make install
- cd /usr/local/nginx/sbin
- 启动:./nginx 或者 ./nginx -c /usr/local/nginx/conf/nginx.conf
- 停止:./nginx -s stop或者./nginx -s quit 或者 ps -ef|grep nginx
- 查到pid ,kill -QUIT pid 或者kill -TERM pid
- 重启:./nginx -s reload
可以通过Vi命令修改,也可以通过xftp下载本地使用notepad++修改使用
vi /usr/local/nginx/conf/nginx.conf
端口号改成9092(随便挑个端口),将localhost修改为服务器的公网ip地址。

访问地址 http://192.168.6.77:9092/
至此,linux安装完毕
由于目标服务器IP访问限制,只允许局域网内部指定服务器访问,其他服务器无法直接访问,此时,可以在指定服务器部署nginx,配置网络代理,以实现局域网其他服务器通过访问指定服务器,间接访问目标服务器(10.10.8.200)
- # 将http://10.10.8.200:81映射到本地9091端口
- server {
- listen 9091;
- server_name localhost;
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- location / {
- root html;
- index index.html index.htm;
- proxy_pass http://10.10.8.200:81;
- }
- }

- #进入安装目录
- cd /usr/local/nginx/sbin
- ./nginx -s reload

查看nginx进程是否启动:
ps -ef | grep nginx
vi /etc/init.d/nginx
- #! /bin/bash
- # chkconfig: - 85 15
- PATH=/usr/local/nginx
- DESC="nginx daemon"
- NAME=nginx
- DAEMON=$PATH/sbin/$NAME
- CONFIGFILE=$PATH/conf/$NAME.conf
- PIDFILE=$PATH/logs/$NAME.pid
- SCRIPTNAME=/etc/init.d/$NAME
- set -e
- [ -x "$DAEMON" ] || exit 0
- do_start() {
- $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
- }
- do_stop() {
- $DAEMON -s stop || echo -n "nginx not running"
- }
- do_reload() {
- $DAEMON -s reload || echo -n "nginx can't reload"
- }
- case "$1" in
- start)
- echo -n "Starting $DESC: $NAME"
- do_start
- echo "."
- ;;
- stop)
- echo -n "Stopping $DESC: $NAME"
- do_stop
- echo "."
- ;;
- reload|graceful)
- echo -n "Reloading $DESC configuration..."
- do_reload
- echo "."
- ;;
- restart)
- echo -n "Restarting $DESC: $NAME"
- do_stop
- do_start
- echo "."
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
- exit 3
- ;;
- esac
- exit 0
将上方脚本代码cp到vi的nginx文件中,修改其中的PATH路径改为自己的安装路径。然后授权
chmod a+x /etc/init.d/nginx
- /etc/init.d/nginx start
- /etc/init.d/nginx stop
-
- chkconfig --add /etc/init.d/nginx
-
- service nginx start
- service nginx stop
-
- chkconfig nginx on
- chkconfig nginx off