需求:

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]#

标签: nginx, root, proxy, log, pid, logs, error

相关文章推荐

添加新评论,含*的栏目为必填