需求:
1:将http://192.168.1.225:9080/building/ 通过代理http://192.168.1.225:8081/building/访问。
[root@localhost conf]# vi nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8081;
server_name localhost;
root /app/nginx/entity-vue/;
location ^~/building/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
#rewrite ^/building/(.*)$ /$1 break;
proxy_pass http://192.168.1.225:9080/building/;
}
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
"nginx.conf" 124L, 2968C written
[root@localhost conf]# cd ..
[root@localhost nginx]# ll
total 4
drwx------ 2 nginx root 6 May 13 15:00 client_body_temp
drwxr-xr-x 2 root root 4096 Jun 1 10:43 conf
drwxr-xr-x 3 root root 57 Jun 1 09:25 entity-vue
drwx------ 2 nginx root 6 May 13 15:00 fastcgi_temp
drwxr-xr-x 2 root root 40 May 13 14:59 html
drwxr-xr-x 2 root root 58 May 13 15:00 logs
drwx------ 2 nginx root 6 May 13 15:00 proxy_temp
drwxr-xr-x 2 root root 19 May 13 14:59 sbin
drwx------ 2 nginx root 6 May 13 15:00 scgi_temp
drwx------ 2 nginx root 6 May 13 15:00 uwsgi_temp
[root@localhost nginx]# ./sbin/nginx -s reload
nginx: [error] invalid PID number "" in "/app/nginx/logs/nginx.pid"
[root@localhost nginx]# cat /app/nginx/logs/nginx.pid
[root@localhost nginx]# rm /app/nginx/logs/nginx.pid
rm: remove regular empty file ‘/app/nginx/logs/nginx.pid’? y
[root@localhost nginx]# ./sbin/nginx -s reload
nginx: [error] open() "/app/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost nginx]# ./sbin/nginx -c ./conf/nginx.conf
[root@localhost nginx]# ./sbin/nginx -s reload
[root@localhost nginx]# ps -ef|grep nginx
root 7854 1 0 10:45 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nginx 7864 7854 0 10:45 ? 00:00:00 nginx: worker process
root 7871 7119 0 10:45 pts/1 00:00:00 grep --color=auto nginx
[root@localhost nginx]# netstat -tunlp|grep LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1187/sshd: /usr/sbi
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1358/master
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 7854/nginx: master
tcp6 0 0 127.0.0.1:18005 :::* LISTEN 26243/java
tcp6 0 0 :::22 :::* LISTEN 1187/sshd: /usr/sbi
tcp6 0 0 :::9080 :::* LISTEN 755/java
tcp6 0 0 ::1:25 :::* LISTEN 1358/master
tcp6 0 0 :::18080 :::* LISTEN 26243/java
tcp6 0 0 :::38496 :::* LISTEN 22669/java
tcp6 0 0 :::8898 :::* LISTEN 5312/java
tcp6 0 0 :::8899 :::* LISTEN 5498/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 26945/java
tcp6 0 0 127.0.0.1:28005 :::* LISTEN 26212/java
tcp6 0 0 :::2181 :::* LISTEN 22669/java
tcp6 0 0 :::9994 :::* LISTEN 26243/java
tcp6 0 0 :::16010 :::* LISTEN 22669/java
tcp6 0 0 192.168.1.225:9997 :::* LISTEN 26212/java
tcp6 0 0 127.0.0.1:38126 :::* LISTEN 22669/java
tcp6 0 0 127.0.0.1:38318 :::* LISTEN 22669/java
tcp6 0 0 :::8080 :::* LISTEN 26945/java
tcp6 0 0 :::28080 :::* LISTEN 26212/java
[root@localhost nginx]# cat ./conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8081;
server_name localhost;
root /app/nginx/entity-vue/;
location ^~/building/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
#rewrite ^/building/(.*)$ /$1 break;
proxy_pass http://192.168.1.225:9080/building/;
}
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@localhost nginx]# cat /app/nginx/logs/nginx.pid
7854
2:将http://192.168.1.225:8898/building-gis/ 通过代理http://192.168.1.225:8081/building-gis/访问。
[root@localhost nginx]#
[root@localhost nginx]# vi ./conf/nginx.conf
#rewrite ^/building/(.*)$ /$1 break;
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8081;
server_name localhost;
root /app/nginx/entity-vue/;
location ^~/building/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
#rewrite ^/building/(.*)$ /$1 break;
proxy_pass http://192.168.207.225:9080/building/;
}
location ^~/building-gis/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://192.168.1.225:8898/building-gis/;
}
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
}
#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;
}
"./conf/nginx.conf" 131L, 3270C written
[root@localhost nginx]# ./sbin/nginx -s reload
[root@localhost nginx]#