欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在Linux上使用Nginx部署静态网页

最编程 2024-02-02 11:41:18
...

安装nginx

1、在线安装方法

sudo yum install nginx

安装完后运行

[root@Lrw888 local]# nginx

查询nginx.conf是否正确

[root@Lrw888 local]# nginx -t

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

2、离线安装方法

安装环境

yum install gcc
yum install pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel

在usr/local目录下新建nginx文件夹

cd /usr/local
mkdir nginx

进入nginx文件夹
cd nginx

下载nginx的tar包
wget http://nginx.org/download/nginx-1.9.7.tar.gz

解压tar
tar -zxvf nginx-1.9.7.tar.gz

安装nginx
./configure

执行make
make

执行make install
make install

进入sbin
cd sbin

启动
sudo ./nginx

查询nginx.conf是否正确
/usr/local/nginx/sbin/nginx -t

部署静态文件

(配置 nginx.conf,

假如你的静态网页文件夹路径是:/usr/local/nginx/nginx-1.9.7/web/,则配置如下)

cd nginx
vim conf/nginx.conf

server {
listen 80;
server_name _;
#root /usr/local/nginx/nginx-1.9.7/web/; #站点根目录
#index index.html;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/local/nginx/nginx-1.9.7/web/;
index index.html;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

重启:

在线安装的:

nginx -s reload

离线安装的:

./sbin/nginx -s reload

 

部署应用服务器配置

只需在server配置项里面增加

 

 server {

    listen       80;

    server_name  localhost;

 

    proxy_set_header Host $host;

    proxy_set_header Referer $http_referer;

    proxy_set_header Cookie $http_cookie;

    proxy_set_header X_Real_IP $remote_addr;

    proxy_set_header X_Forwarded_For $proxy_add_x_forwarded_for;

    proxy_send_timeout 180s;

    proxy_read_timeout 180s;

 

 

    location / {

            root   /usr/local/nginx/nginx-1.9.7/web/;

            index  index.html;

        }

 

 

    location /grid {

        proxy_cookie_path /grid/ /;

        proxy_pass http://localhost:8080/grid/;

    }

8080就是应用服务器(jar)监听的端口。